|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Trouble using sql IN statement with list of datetimesparameter like so: --Example input data: '2005-12-21 15:55:26.053, 2005-12-21 15:41:35.600, 2005-12-21 15:23:21.647, 2005-12-20 19:15:27.180' declare @RequestCreationTimeList nvarchar(500) Select dbo.MyTable.RequestCreationTime, FieldA, FieldB where ( convert(varchar, dbo.MyTable.RequestCreationTime,21) IN (' + @RequestCreationTimeList + ') ) I am not able to get any matches... I have a feeling it has to do with not having quotes in between the individual datatime stamp. This works: select dbo.MyTable.RequestCreationTime, convert(varChar,dbo. MyTable.RequestCreationTime,121) as [String] from dbo.MyTable where (convert(varchar,dbo.MyTable.RequestCreationTime,21) = '2005-12-21 15:55:26.053') -- output: 2005-12-21 15:55:26.053 2005-12-21 15:55:26.053 So I'm pretty sure my formatting is correct... If any one has any insight on this I would be most appreciative. Thanks, Jeff You can't pass a delimited string inside an IN expression without preparing
the query string (i.e. without using dynamic SQL). Try this function by Dejan Sarka: http://solidqualitylearning.com/blogs/dejan/archive/2004/10/22/200.aspx ML --- http://milambda.blogspot.com/ |
|||||||||||||||||||||||