﻿<?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 2008 / SQL Server 2008 - General  / IF EXISTS Logic / 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>Sun, 19 May 2013 23:56:18 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: IF EXISTS Logic</title><link>http://www.sqlservercentral.com/Forums/Topic1391794-391-1.aspx</link><description>Why are you trying to use dynamic sql. It's look like you need full outer join:[code="sql"]SELECT ISNULL(t.Column_Name, v.Column_Name) AS Column_Name           ,CASE WHEN  t.Column_Name IS NULL THEN v.Value                     ELSE t.Value            END AS ValueFROM   @Temp_Table tFULL OUTER JOIN St_Value v ON v.Column_Name	= t.Column_Name[/code]</description><pubDate>Mon, 03 Dec 2012 02:36:20 GMT</pubDate><dc:creator>Eugene Elutin</dc:creator></item><item><title>IF EXISTS Logic</title><link>http://www.sqlservercentral.com/Forums/Topic1391794-391-1.aspx</link><description>Hi Team,I am having a temp Table [b]"@Temp_Table[/b]" and a physical Table [b]"St_Value"[/b][u]@Temp_Table Contains[/u]Case1: Column_Name	|	Value------------------------------Col1			123Col2			NULL[u]"St_value" Contains[/u]Column_Name	|	Value-------------------------------Col1			123Col2			582Col3	[b]My Query is :[/b]if @temp_table contains Col1 and its value thenselect "col1 : 123"for record col2 there is no value (NULL) thenonly the column lable should be include.select "Col1 :123,           Col2 :"then for remaining records it should check in "St_value" tableFinal string should beselect "Col1 :123,           Col2 :          Col3 :456"Exact Requirement :If temp table contains label "column_name" and its "value" then only Column_Name : Value should be includedelse only column_name should be included, for remaining records it should check in physical table.am using below logic, but its not working.Please help..SELECT @query1 = IF EXISTS (SELECT col1 from @Temp_Table)THEN'Col1: ' +rtrim(Col1) + ' (Value ' +  rtrim(convert(varchar, Value,107)) + ')' +CHAR(10)ELSE'Col1: ' ' Value : 'ELSECASE WHEN Col1 IS  NULL or Col1 = '' THEN ''ELSE CASE WHEN Value IS null then'Col1: ' + rtrim(Col1) +CHAR(10)ELSE 'Col1: ' +rtrim(Col1) + ' (Expires ' +  rtrim(convert(varchar, Value,107)) + ')' +CHAR(10)ENDEND+from St_ValuePlease Help...?</description><pubDate>Mon, 03 Dec 2012 01:01:22 GMT</pubDate><dc:creator>Minnu</dc:creator></item></channel></rss>