Showing posts with label statement. Show all posts
Showing posts with label statement. Show all posts

Monday, March 12, 2012

Import data from excel into tables

hi
I want to import data from excel into table in sql server
while execution this statement
select *
into SQLServerTable FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=D:\testing.xls;HDR=YES',
'SELECT * FROM [Sheet1$]')
i got this error
[Microsoft][ODBC SQL Server Driver][SQL Server]OLE DB provider
'Microsoft.Jet.OLEDB.4.0' reported an error. ERROR [01000]
[Microsoft][ODBC SQL Server Driver][SQL Server][OLE/DB provider returned
message:
Could not find installable ISAM.
Any one find me solution and reply where it went wrongHi
It is better practice to create the table and then using INSERT...SELECT
rather than SELECT.. INTO.
I think you should be using datasource and not database therefore (this is
untested!) try:
SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'DataSource=D:\testing.xls;Extended Properties=Excel 8.0;HDR=YES', Sheet1$)
John
"Chinnappa" <Chinnappa@.discussions.microsoft.com> wrote in message
news:99E608C6-BBBF-43A4-B7AE-DF2D0318C79D@.microsoft.com...
> hi
>
> I want to import data from excel into table in sql server
> while execution this statement
> select *
> into SQLServerTable FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
> 'Excel 8.0;Database=D:\testing.xls;HDR=YES',
> 'SELECT * FROM [Sheet1$]')
> i got this error
>
> [Microsoft][ODBC SQL Server Driver][SQL Server]OLE DB provider
> 'Microsoft.Jet.OLEDB.4.0' reported an error. ERROR [01000]
> [Microsoft][ODBC SQL Server Driver][SQL Server][OLE/DB provider returned
> message:
> Could not find installable ISAM.
> Any one find me solution and reply where it went wrong
>

Friday, March 9, 2012

import CSV file?

how can i import CSV data to sql server using sql statement?
thanksSee the documentation for BULK INSERT

http://msdn2.microsoft.com/en-us/library/ms188365.aspx
|||it is difficult to create XML file, how i can create xml for CSV file from table that i will have to import into?
thanks

Sunday, February 19, 2012

Implied If Statements

What would be the best function to do an implied if statement in SQL?
ex.
if column A = 2
then Column B/Column C
otherwise Column B
Thanks for your help again!!Use a CASE expression:
CASE ColA
WHEN 2 THEN ColB / ColC
ELSE ColB
END
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Barce5" <Barce5@.discussions.microsoft.com> wrote in message
news:18BA472F-EF66-42FE-A0BC-C19C201642AF@.microsoft.com...
> What would be the best function to do an implied if statement in SQL?
> ex.
> if column A = 2
> then Column B/Column C
> otherwise Column B
> Thanks for your help again!!|||Use a CASE expression.
Example:
select case when colA = 2 then colB/nullif(colC, 0) else colB end
from yourTable
go
AMB
"Barce5" wrote:

> What would be the best function to do an implied if statement in SQL?
> ex.
> if column A = 2
> then Column B/Column C
> otherwise Column B
> Thanks for your help again!!