﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / Development  / Query quesiton / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 18 Jun 2013 20:07:45 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Query quesiton</title><link>http://www.sqlservercentral.com/Forums/Topic1261985-145-1.aspx</link><description>Thanks Gail, I got it from your point. Thanks to others as well for describing.</description><pubDate>Fri, 09 Mar 2012 05:23:32 GMT</pubDate><dc:creator>sqlnaive</dc:creator></item><item><title>RE: Query quesiton</title><link>http://www.sqlservercentral.com/Forums/Topic1261985-145-1.aspx</link><description>Because select * from #t1 where id in(@p2) is completely and totally equivalent to select * from #t1 where id = @p2. Each item in an IN (variable, parameter or constant) is considered to be a single valueTo specify variables in an IN, it would be like this: select * from #t1 where id in(@p1, @p2, @p3, @p4)</description><pubDate>Fri, 09 Mar 2012 03:39:59 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>RE: Query quesiton</title><link>http://www.sqlservercentral.com/Forums/Topic1261985-145-1.aspx</link><description>I agree but why does not it works like this ? I mean is there something more precise or some doc where I can get deep understanding on this ?</description><pubDate>Fri, 09 Mar 2012 03:04:24 GMT</pubDate><dc:creator>sqlnaive</dc:creator></item><item><title>RE: Query quesiton</title><link>http://www.sqlservercentral.com/Forums/Topic1261985-145-1.aspx</link><description>Because you need to run it as Dynamic SQL, using the EXEC command:[code="sql"]EXEC(N'SELECT * FROM #Test1 WHERE Test_Text IN (' + @P1 + ')');[/code]What you have is SQL probably attempting to find a match to the entire varchar ''xyz','tln','tprq'', not three seperate values.</description><pubDate>Fri, 09 Mar 2012 02:46:20 GMT</pubDate><dc:creator>BrainDonor</dc:creator></item><item><title>RE: Query quesiton</title><link>http://www.sqlservercentral.com/Forums/Topic1261985-145-1.aspx</link><description>Because, as Gianluca and BrainDonor have already mentioned, you need to use a split function or dynamic SQL.  Make sure you understand the [url=http://www.sommarskog.se/dynamic_sql.html]implications [/url]of the latter.John</description><pubDate>Fri, 09 Mar 2012 02:42:16 GMT</pubDate><dc:creator>John Mitchell-245523</dc:creator></item><item><title>RE: Query quesiton</title><link>http://www.sqlservercentral.com/Forums/Topic1261985-145-1.aspx</link><description>create table #t1(id varchar(5))insert into #t1 values('xyz'), ('kkl'), ('tln'), ('cxz'), ('dfa'), ('tprq')select * from #t1Declare @p1 varchar(50) = 'xyz,tln,tprq'Declare @p2 varchar(50) = ''''+replace(@p1, ',', ''',''')+''''select @p1select @p2select * from #t1 where id in(@p2)Why teh last select does not return any value inspite of @p2 having the correct presentation of condition ?</description><pubDate>Fri, 09 Mar 2012 02:31:41 GMT</pubDate><dc:creator>sqlnaive</dc:creator></item><item><title>RE: Query quesiton</title><link>http://www.sqlservercentral.com/Forums/Topic1261985-145-1.aspx</link><description>As Gianluca has shown, one way to do this is to split @P1, because it is no use in it's current format as a parameter. Col1 would have to have a value of 'xyz,tln,tprq' in one row.Another option is to use Dynamic SQL, but this would require a change in the format of @P1 - this may be an option for you. Pay attention to the number of single quotes required in the value of @P1:[code="sql"]CREATE TABLE #Test1(	Test_Text	VarChar(20)	);	INSERT INTO #Test1(Test_Text)VALUES('abc'),('cde'),('fgh'),('xyz'),('123'),('tln'),('456'),('tprq');DECLARE @P1 VarChar(30);SET @P1 = '''xyz'''+','+'''tln'''+','+'''tprq''';SELECT @P1;EXEC(N'SELECT * FROM #Test1 WHERE Test_Text IN (' + @P1 + ')');[/code]</description><pubDate>Tue, 06 Mar 2012 02:19:35 GMT</pubDate><dc:creator>BrainDonor</dc:creator></item><item><title>RE: Query quesiton</title><link>http://www.sqlservercentral.com/Forums/Topic1261985-145-1.aspx</link><description>Use a split function: [url]http://www.sqlservercentral.com/articles/Tally+Table/72993/[/url]</description><pubDate>Tue, 06 Mar 2012 01:51:08 GMT</pubDate><dc:creator>spaghettidba</dc:creator></item><item><title>Query quesiton</title><link>http://www.sqlservercentral.com/Forums/Topic1261985-145-1.aspx</link><description>how can i achieve this?Declare @p1 = 'xyz,tln,tprq'select * from table1 where col1 in('xyz','tln','tprq')</description><pubDate>Tue, 06 Mar 2012 00:47:20 GMT</pubDate><dc:creator>sqlnaive</dc:creator></item></channel></rss>