Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Multiple Values insert

Author  Topic 

swathigardas
Posting Yak Master

149 Posts

Posted - 2008-12-12 : 07:30:27
Hi in the stored Procedure i would get multiple values concatenated for a single variable..

i want to insert mulitples records using the values in this variable

I'm trying to bulid a query something like this

INSERT INTO TEmployee_System_Role (Role_NBR,Create_DT,Employee_NBR)
VALUES (@Role_NBR,GETDATE(),(select employee_nbr from tEmployee where employee_nbr in (@employee_numbers))

The error i receive is

Subqueries are not allowed in this context. Only scalar expressions are allowed.


Is there any way to do this...
Please Suggest Me..
Thanks Before Hand

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-12-12 : 08:34:33
INSERT INTO TEmployee_System_Role (Role_NBR,Create_DT,Employee_NBR)
SELECT @Role_NBR,GETDATE(),employee_nbr
from tEmployee
where employee_nbr in (@employee_numbers))

you can't do that in a where clause, you'll have to parse the values
search this site ParseValues to get some ideas on how

Jim
Go to Top of Page

swathigardas
Posting Yak Master

149 Posts

Posted - 2008-12-12 : 09:13:35
But i would be getting multiple values for employee numbers

the variable will be holding values like '1,2,3,4,5,6,7,8,9,10'
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-12 : 09:21:51
[code]
INSERT INTO TEmployee_System_Role (Role_NBR,Create_DT,Employee_NBR)
SELECTY @Role_NBR,GETDATE(), employee_nbr
from tEmployee
where ','+ @employee_numbers +',' LIKE '%,'+ CAST(employee_nbr AS varchar(20)) + ',%'[/code]
Go to Top of Page

swathigardas
Posting Yak Master

149 Posts

Posted - 2008-12-12 : 10:15:51
Exactly... Its Working Fine.... Thanks a Lot VIshakh...
Cant Stop Applauding you
I dint Expect that it would be so simple.. I was breaking my head on this since long
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-12 : 10:25:41
No problem...you're welcome
Go to Top of Page
   

- Advertisement -