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.
| Author |
Topic |
|
celene
Starting Member
1 Post |
Posted - 2003-01-20 : 13:48:04
|
declare @x varchar(50)set @x='1,2,3'select * from machines where machine_id in (@x)Server: Msg 245, Level 16, State 1, Line 3Syntax error converting the varchar value '1,2,3' to a column of data type int.select * from machines where machine_id in (1,2,3) "OK"What I can do to execute the first query well |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
|
|
zipman1952
Starting Member
14 Posts |
Posted - 2003-01-20 : 14:38:50
|
| declare @x varchar(50), @sql varchar (100)set @x='1,2,3' select @sql ='select * from machines where machine_id in (' + @x + ')'exec (@sql) |
 |
|
|
harshal_in
Aged Yak Warrior
633 Posts |
Posted - 2003-01-20 : 23:34:10
|
| hi, why do u want to use dynamic sql ?u can use this function to convert the csv to int.I had found the following function on this site you can use this:Create Function dbo.CsvToInt ( @Array varchar(1000)) returns @IntTable table (IntValue int)ASbegin declare @separator char(1) set @separator = ',' declare @separator_position int declare @array_value varchar(1000) set @array = @array + ',' while patindex('%,%' , @array) <> 0 begin select @separator_position = patindex('%,%' , @array) select @array_value = left(@array, @separator_position - 1) Insert @IntTable Values (Cast(@array_value as int)) select @array = stuff(@array, 1, @separator_position, '') end returnendor make a search for csv on this site there is plenty of info.Regards,harshalExpect the UnExpected |
 |
|
|
|
|
|
|
|