Inserting table in SQL server using Cursor -
i trying import excel file sql , file has 3 columns : box - code - validity using following query
use [libatel] go set ansi_nulls on go set quoted_identifier on go alter procedure [dbo].[getdataexcel] declare c cursor select box, code , validity openrowset('microsoft.ace.oledb.12.0', 'excel 12.0;database=c:\barcodes.xlsx;hdr=yes', 'select box, code , validity [sheet1$]') declare @code bigint declare @box bigint declare @validity date begin open c fetch next c @code,@box,@validity while @@fetch_status = 0 begin select @box = box,@code = barcode,@validity =validitydate cards insert cards (barcode,box,validitydate) values (@box,@code,@validity) fetch next c @box,@code,@validity end close c deallocate c end
i getting folowing
11155232026 1 2013-05-18 1 11155232026 2013-05-18 ... ...
this first line , box , code changing places on each line , doing wrong ?
your second fetch
has wrong column order:
fetch next c @code,@box,@validity ... fetch next c @box,@code,@validity
another problem statement:
select @box = box,@code = barcode,@validity =validitydate cards
that fetches random row cards
table, discarding values cursor. perhaps clarify line supposed do?
Comments
Post a Comment