Click here to Skip to main content
15,881,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello
I need urgently your help. I have a stored procedure with 1 single parameter (@code)
SQL
e.g create PROCEDURE george
@code int
begin 
...........


the send me an excel which has the codes ( for @code) that i must to execute
e.g excel has 1 column (code) and 3 rows (1111, 2222,3333)

the problem is when i am going to execute it i have to give
SQL
EXEC george @code = '1111'
EXEC george @code = '2222'
EXEC george @code = '3333'


in order to execute ( in series). but when the excel file have 100 rows this is a problem

could you tell a way ( to write different maybe the procedure or something else) so that i have to give only ONCE execution for the procedure and this executes all the codes from the excel (( in series) one after the other.
thanks in advance
Posted
Updated 13-Nov-15 20:08pm
v2
Comments
ZurdoDev 13-Nov-15 15:17pm    
You can use a cursor in SQL and take a delimited list.

1 solution

You can pass comma separated list of parameters as single parameter. Then - inside a sp - you have to split values into several rows. How? Please, see: Using comma separated value parameter strings in SQL IN clauses[^]

But i'd suggest to re-think your programme and create connection between Excel file and sql server database. Then you'll be able to select data based on relationship between databases, even if an Excel file will be having over 1M records. Another way is to create linked server[^].
Using a SQL Server Linked Server to Query Excel Files[^]
How to import data from Excel to SQL Server [^]
Moving Data From Excel to SQL Server - 10 Steps to Follow[^]
Simple way to import data into SQL Server[^]
 
Share this answer
 
v4
Comments
Abhinav S 14-Nov-15 5:18am    
5!
Maciej Los 14-Nov-15 16:48pm    
Thank you, Abhinav.
King Fisher 14-Nov-15 7:11am    
my 5 .,
hi maciej ,
how ru?
Maciej Los 14-Nov-15 16:49pm    
Thank you, King. I'm fine. And how are you?
King Fisher 23-Nov-15 4:35am    
I'm very good,thank you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900