Click here to Skip to main content
15,914,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
select id,name from MyCylenderMaster where id in (@ids)

in above query i got error Input string was not in correct format because the id has datatype int and @ids has datatype nvarchar(max), my @ids values are like
@ids=1,2,3,4,5.......
is there any way to sove that problem.
Posted
Comments
dhiraj mane 28-Jun-14 7:14am    
it works....thanks.
but i have 1 more problem pls check it
EXEC('UPDATE MyCylenderMaster SET out_date='+ @date +',dc_no ='+@out_id+' where Id in('+@cylender_no+')')
it show error to date like
Incorrect syntax near '1'.
Manjeet349 6-Jul-14 6:33am    
just pass your varchar or datetime variables in dynamic query like :

'''+@date+'''

this will convert your date value to '1-1-2014' and that's the error in your case as you are getting out_date=1-1-2014.

i hope this will help.

sorry for late reply. i was on vacation... :)

 
Share this answer
 
Comments
Maciej Los 27-Jun-14 10:42am    
+5
As your requirement, you don't need to convert your comma-delimited list to int but convert your column id to nvarchar on the fly.

And as your problem, you can use EXEC() function:

EXEC('select id,name from MyCylenderMaster where id in ('+@ids+')')

OR CHARINDEX() function like:

CHARINDEX(CONVERT(nvarchar,id),@ids,0) > 0
 
Share this answer
 
Comments
dhiraj mane 28-Jun-14 6:28am    
it works....thanks.
but i have 1 more problem pls check it
EXEC('UPDATE MyCylenderMaster SET out_date='+ @date +',dc_no ='+@out_id+' where Id in('+@cylender_no+')')
it show error to date like
Incorrect syntax near '1'.

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