<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; CASE Statement/Expression Examples and Explanation</title>
	<atom:link href="http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:54:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Clark</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-57709</link>
		<dc:creator>Clark</dc:creator>
		<pubDate>Wed, 18 Nov 2009 17:51:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-57709</guid>
		<description>Thanks Prabhakar, your sample code lead me to the right track faced with a similar situation.  Can you give me a quick example of how you would handle the NULL values in this situation? 

Thanks...</description>
		<content:encoded><![CDATA[<p>Thanks Prabhakar, your sample code lead me to the right track faced with a similar situation.  Can you give me a quick example of how you would handle the NULL values in this situation? </p>
<p>Thanks&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Tkatch</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-57107</link>
		<dc:creator>Brian Tkatch</dc:creator>
		<pubDate>Wed, 28 Oct 2009 13:24:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-57107</guid>
		<description>@Asma Qureshi

What is the problem?

Also, you can use a simple case expression:

DECLARE @TestVal varchar
SET @TestVal = ‘Asma’
SELECT
CASE @TestVal
WHEN  &#039;Asma&#039; THEN &#039;Top 1&#039;
ELSE &#039;Other&#039;
END</description>
		<content:encoded><![CDATA[<p>@Asma Qureshi</p>
<p>What is the problem?</p>
<p>Also, you can use a simple case expression:</p>
<p>DECLARE @TestVal varchar<br />
SET @TestVal = ‘Asma’<br />
SELECT<br />
CASE @TestVal<br />
WHEN  &#8216;Asma&#8217; THEN &#8216;Top 1&#8242;<br />
ELSE &#8216;Other&#8217;<br />
END</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tejas Shah</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-57103</link>
		<dc:creator>Tejas Shah</dc:creator>
		<pubDate>Wed, 28 Oct 2009 13:19:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-57103</guid>
		<description>@Asma,

Ofcourse it will work.

Tejas</description>
		<content:encoded><![CDATA[<p>@Asma,</p>
<p>Ofcourse it will work.</p>
<p>Tejas</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Asma Qureshi</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-57099</link>
		<dc:creator>Asma Qureshi</dc:creator>
		<pubDate>Wed, 28 Oct 2009 08:59:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-57099</guid>
		<description>Sub: CASE Statement  in SQL server  

 Can you please tell me that 
CASE Statement  working with String / Varchar

means i want to check some varchar values


DECLARE @TestVal varchar
SET @TestVal = &#039;Asma&#039;
SELECT
CASE
WHEN @TestVal =&#039;Asma&#039; THEN &#039;Top 1&#039;
ELSE &#039;Other&#039;
END</description>
		<content:encoded><![CDATA[<p>Sub: CASE Statement  in SQL server  </p>
<p> Can you please tell me that<br />
CASE Statement  working with String / Varchar</p>
<p>means i want to check some varchar values</p>
<p>DECLARE @TestVal varchar<br />
SET @TestVal = &#8216;Asma&#8217;<br />
SELECT<br />
CASE<br />
WHEN @TestVal =&#8217;Asma&#8217; THEN &#8216;Top 1&#8242;<br />
ELSE &#8216;Other&#8217;<br />
END</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Tkatch</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-56132</link>
		<dc:creator>Brian Tkatch</dc:creator>
		<pubDate>Thu, 24 Sep 2009 13:39:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-56132</guid>
		<description>@krish

Why not use REPLACE() for the entire string? No WHILE loop or anything, just a simple REPLACE(@name, &#039;;&#039;, &#039;&#039;)</description>
		<content:encoded><![CDATA[<p>@krish</p>
<p>Why not use REPLACE() for the entire string? No WHILE loop or anything, just a simple REPLACE(@name, &#8216;;&#8217;, &#8221;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: krish</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-56123</link>
		<dc:creator>krish</dc:creator>
		<pubDate>Thu, 24 Sep 2009 11:57:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-56123</guid>
		<description>I am getting problem in removing special character from string 
  I am doing like this :I want to do multiple sepcial charcter remove from this but i am able to replace only on charcter

 
declare @name varchar(10)
declare @currentchar varchar(10)
declare @backUp  varchar(10)
declare @len int
declare @i int
set @name=&#039;;kri;pal&#039;
set @len=len(@name)
set @i=1
declare @Kk  varchar(20)
 WHILE @i &lt;= @len
         BEGIN         

             SET @currentchar = SUBSTRING(@name,@i, 1)
                      select
           @backUp =(case when (@currentchar=&#039;;&#039; )then 
                  replace(@currentchar,&#039;;&#039; ,&#039;&#039;)
           else 
            @currentchar end)

        
       
      
         
                    set @kk=isnull(@kk,&#039;&#039;)+@backUp  
             SET @i = @i + 1         
         END

pls help me urgent:</description>
		<content:encoded><![CDATA[<p>I am getting problem in removing special character from string<br />
  I am doing like this :I want to do multiple sepcial charcter remove from this but i am able to replace only on charcter</p>
<p>declare @name varchar(10)<br />
declare @currentchar varchar(10)<br />
declare @backUp  varchar(10)<br />
declare @len int<br />
declare @i int<br />
set @name=&#8217;;kri;pal&#8217;<br />
set @len=len(@name)<br />
set @i=1<br />
declare @Kk  varchar(20)<br />
 WHILE @i &lt;= @len<br />
         BEGIN         </p>
<p>             SET @currentchar = SUBSTRING(@name,@i, 1)<br />
                      select<br />
           @backUp =(case when (@currentchar=&#039;;&#039; )then<br />
                  replace(@currentchar,&#039;;&#039; ,&#039;&#039;)<br />
           else<br />
            @currentchar end)</p>
<p>                    set @kk=isnull(@kk,&#039;&#039;)+@backUp<br />
             SET @i = @i + 1<br />
         END</p>
<p>pls help me urgent:</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chris</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-52775</link>
		<dc:creator>chris</dc:creator>
		<pubDate>Fri, 05 Jun 2009 16:04:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-52775</guid>
		<description>I am attempting to update table1.status with a 1 if it exists within table2 otherwise i want it to update with a 0 if it does not. the statement I have is as follows

Update
[table1]
SET Status = (
case
when 
(Select status from table1 inner join table2
on table1.ID = table2.ID)
then &#039;1&#039;
else &#039;0&#039;</description>
		<content:encoded><![CDATA[<p>I am attempting to update table1.status with a 1 if it exists within table2 otherwise i want it to update with a 0 if it does not. the statement I have is as follows</p>
<p>Update<br />
[table1]<br />
SET Status = (<br />
case<br />
when<br />
(Select status from table1 inner join table2<br />
on table1.ID = table2.ID)<br />
then &#8216;1&#8242;<br />
else &#8216;0&#8242;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: joseph jelasker</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-51365</link>
		<dc:creator>joseph jelasker</dc:creator>
		<pubDate>Tue, 28 Apr 2009 14:50:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-51365</guid>
		<description>Nice article. Can you pls tell me how to insert a null value in the database while mentioning the field name in the inser query.

i am getting value from textBox of non-required field user may not key-in any value.

pls guide me the way to write a stored procedure to come across this issue</description>
		<content:encoded><![CDATA[<p>Nice article. Can you pls tell me how to insert a null value in the database while mentioning the field name in the inser query.</p>
<p>i am getting value from textBox of non-required field user may not key-in any value.</p>
<p>pls guide me the way to write a stored procedure to come across this issue</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-51048</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Thu, 16 Apr 2009 18:43:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-51048</guid>
		<description>How about this?

Select id, name
CASE WHEN AGE+@SomeVariable&lt;17 THEN ‘Young’
ELSE cast(AGE as varchar(5)) END as NewAge
from users

Where NewAge would return a string. or:

Select id, name, Age,
CASE WHEN AGE+@SomeVariable&lt;17 THEN ‘Young’
ELSE &#039;&#039; END as SubjectiveAge
from users

Where Age would contain the age, and SubjectiveAge would contain &#039;Young&#039; or an empty string.</description>
		<content:encoded><![CDATA[<p>How about this?</p>
<p>Select id, name<br />
CASE WHEN AGE+@SomeVariable&lt;17 THEN ‘Young’<br />
ELSE cast(AGE as varchar(5)) END as NewAge<br />
from users</p>
<p>Where NewAge would return a string. or:</p>
<p>Select id, name, Age,<br />
CASE WHEN AGE+@SomeVariable&lt;17 THEN ‘Young’<br />
ELSE &#8221; END as SubjectiveAge<br />
from users</p>
<p>Where Age would contain the age, and SubjectiveAge would contain &#8216;Young&#8217; or an empty string.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-50918</link>
		<dc:creator>Imran Mohammed</dc:creator>
		<pubDate>Mon, 13 Apr 2009 05:45:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-50918</guid>
		<description>@Hitendra

Can you rephrase your question please. 

I could not understand your question.

If you want to pass column name as parameter, then you can do that using dynamic SQL.

Before I suggest you something, I want to make sure I understand your question. Please put your question in very clear form. 

Thanks.
~ IM.</description>
		<content:encoded><![CDATA[<p>@Hitendra</p>
<p>Can you rephrase your question please. </p>
<p>I could not understand your question.</p>
<p>If you want to pass column name as parameter, then you can do that using dynamic SQL.</p>
<p>Before I suggest you something, I want to make sure I understand your question. Please put your question in very clear form. </p>
<p>Thanks.<br />
~ IM.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hitendra</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-50887</link>
		<dc:creator>Hitendra</dc:creator>
		<pubDate>Sun, 12 Apr 2009 09:30:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-50887</guid>
		<description>Hi,

How can we do this

Select id, name,
CASE
     WHEN AGE+@SomeVariable&lt;17 THEN &#039;Young&#039;
     ELSE AGE END
from users

I am trying to run case on a computed field and want to show a text incase the output of that field meets the criteria or simply echo the output.

Cannot use the field computation again, as it includes a subquery, which I don&#039;t think should run again for performance reasons.

Thanks</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>How can we do this</p>
<p>Select id, name,<br />
CASE<br />
     WHEN AGE+@SomeVariable&lt;17 THEN &#8216;Young&#8217;<br />
     ELSE AGE END<br />
from users</p>
<p>I am trying to run case on a computed field and want to show a text incase the output of that field meets the criteria or simply echo the output.</p>
<p>Cannot use the field computation again, as it includes a subquery, which I don&#8217;t think should run again for performance reasons.</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tarique Akhtar</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-47265</link>
		<dc:creator>Tarique Akhtar</dc:creator>
		<pubDate>Tue, 24 Feb 2009 13:27:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-47265</guid>
		<description>informative article</description>
		<content:encoded><![CDATA[<p>informative article</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQLAuthority News - Best Articles on SQLAuthority.com Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-47196</link>
		<dc:creator>SQLAuthority News - Best Articles on SQLAuthority.com Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Tue, 24 Feb 2009 12:07:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-47196</guid>
		<description>[...] SQL SERVER - CASE Statement/Expression Examples and Explanation [...]</description>
		<content:encoded><![CDATA[<p>[...] SQL SERVER &#8211; CASE Statement/Expression Examples and Explanation [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sajith</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-45775</link>
		<dc:creator>Sajith</dc:creator>
		<pubDate>Tue, 20 Jan 2009 12:33:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-45775</guid>
		<description>I have the following CASE Statement . I did it manually.  how can I make it dynamic ?



CASE TourismFilmHeader.RefLanguageID
WHEN &#039;1&#039; then (SELECT TourismLanguageMaster.Language FROM TourismLanguageMaster WHERE Language = &#039;Arabic&#039;)
WHEN &#039;2&#039; then (SELECT TourismLanguageMaster.Language FROM TourismLanguageMaster WHERE Language = &#039;English&#039;)
WHEN &#039;3&#039; then (SELECT TourismLanguageMaster.Language FROM TourismLanguageMaster WHERE Language = &#039;Hindi&#039;)
ELSE &#039;None&#039;
END</description>
		<content:encoded><![CDATA[<p>I have the following CASE Statement . I did it manually.  how can I make it dynamic ?</p>
<p>CASE TourismFilmHeader.RefLanguageID<br />
WHEN &#8216;1&#8242; then (SELECT TourismLanguageMaster.Language FROM TourismLanguageMaster WHERE Language = &#8216;Arabic&#8217;)<br />
WHEN &#8216;2&#8242; then (SELECT TourismLanguageMaster.Language FROM TourismLanguageMaster WHERE Language = &#8216;English&#8217;)<br />
WHEN &#8216;3&#8242; then (SELECT TourismLanguageMaster.Language FROM TourismLanguageMaster WHERE Language = &#8216;Hindi&#8217;)<br />
ELSE &#8216;None&#8217;<br />
END</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rkr</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-45612</link>
		<dc:creator>rkr</dc:creator>
		<pubDate>Wed, 14 Jan 2009 17:04:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-45612</guid>
		<description>I need a return of two values from a case statement as here i am searching for a value in database. when a perticular value is found i need 2 vaues in my result set.
Pls suggest?</description>
		<content:encoded><![CDATA[<p>I need a return of two values from a case statement as here i am searching for a value in database. when a perticular value is found i need 2 vaues in my result set.<br />
Pls suggest?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-44667</link>
		<dc:creator>Imran Mohammed</dc:creator>
		<pubDate>Wed, 10 Dec 2008 03:31:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-44667</guid>
		<description>Sunil ( with dollar sign)

Please write your query here.... 

Thanks,
IM</description>
		<content:encoded><![CDATA[<p>Sunil ( with dollar sign)</p>
<p>Please write your query here&#8230;. </p>
<p>Thanks,<br />
IM</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: $unil</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-44648</link>
		<dc:creator>$unil</dc:creator>
		<pubDate>Tue, 09 Dec 2008 14:43:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-44648</guid>
		<description>I am trying to use a 2 case statements inside one table. both statements work but they dont work together, any ideas??</description>
		<content:encoded><![CDATA[<p>I am trying to use a 2 case statements inside one table. both statements work but they dont work together, any ideas??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mahesh</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-44425</link>
		<dc:creator>Mahesh</dc:creator>
		<pubDate>Fri, 28 Nov 2008 07:44:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-44425</guid>
		<description>Not working ,

	SELECT   
	case when (ResheduleDate = &#039;&#039;) then AppDate else ResheduleDate  end as FinalDate 
	from tbl_Appointments 
	WHERE  ProviderID =  76  and Status = 2  Group by FinalDate


Thanks</description>
		<content:encoded><![CDATA[<p>Not working ,</p>
<p>	SELECT<br />
	case when (ResheduleDate = &#8221;) then AppDate else ResheduleDate  end as FinalDate<br />
	from tbl_Appointments<br />
	WHERE  ProviderID =  76  and Status = 2  Group by FinalDate</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cool</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-44075</link>
		<dc:creator>cool</dc:creator>
		<pubDate>Thu, 06 Nov 2008 06:10:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-44075</guid>
		<description>I am passing two different parameters 1&gt;@Name 2&gt;@Id. Depending on parameter @Name I want to fire select statement on different table. Can I put this in case statement,if yes then how?
for eg:
@name= text1
@Id=87
select col1 from tab1 where id=@Id

@name=text2
@Id=85
select col2 from tab2 where id=@Id

Thanks in advance.</description>
		<content:encoded><![CDATA[<p>I am passing two different parameters 1&gt;@Name 2&gt;@Id. Depending on parameter @Name I want to fire select statement on different table. Can I put this in case statement,if yes then how?<br />
for eg:<br />
@name= text1<br />
@Id=87<br />
select col1 from tab1 where id=@Id</p>
<p>@name=text2<br />
@Id=85<br />
select col2 from tab2 where id=@Id</p>
<p>Thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gugu Ntshangse</title>
		<link>http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-42644</link>
		<dc:creator>Gugu Ntshangse</dc:creator>
		<pubDate>Wed, 10 Sep 2008 10:55:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/#comment-42644</guid>
		<description>Your article is greatly appreciated!!!!!!!!!!!

How do you include an update statement in a case statement xmlDocument.......
eg.

CASE WHEN (@xml.exist(&#039;/ROOT/Trip/RouteItem[@RouteDBId=&quot;875077&quot;]&#039;)) THEN
UPDATE route_details
	SET
		route_details.trip_authority_code = XMLRouteDetails.TripAuthorityNumber,
		route_details.start_route_location_name = XMLRouteDetails.StartLocationName,
		route_details.Start_Date = XMLRouteDetails.StartDate

From OpenXml(@intPointer,&#039;/ROOT/Trip/RouteItem&#039;,3)
	With 
	(
		TripAuthorityNumber int &#039;../@TripAuthorityNumber&#039;,
		StartLocationName varchar(100),
		StartDate smalldatetime
XMLRouteDetails WHERE route_details.trip_authority_code = XMLRouteDetails.TripAuthorityNumber

	-- Rollback the transaction if there were any errors
	IF @@ERROR  0
	 BEGIN
		-- Rollback the transaction
		ROLLBACK

		-- Raise an error and return
		RAISERROR (&#039;Error in updating route in route_details table&#039;, 16, 1)
		RETURN
	 END

	ELSE

	INSERT INTO route_details
	(
		trip_authority_code,
		start_route_location_name,
		Start_Date
)

	Select 	
		@TripID,
		StartLocationName,
		StartDate
from OpenXml(@intPointer,&#039;/ROOT/Trip/RouteItem&#039;,3)
	With 
	(
		TripAuthorityNumber int &#039;../@TripAuthorityNumber&#039;,
		StartLocationName varchar(100),
		StartDate smalldatetime
)
	-- Rollback the transaction if there were any errors
	IF @@ERROR  0
	 BEGIN
		-- Rollback the transaction
		ROLLBACK

		-- Raise an error and return
		RAISERROR (&#039;Error in inserting route into route_details table&#039;, 16, 1)
		RETURN
	 END
	END
	COMMIT
	exec sp_xml_removedocument @intPointer

RETURN</description>
		<content:encoded><![CDATA[<p>Your article is greatly appreciated!!!!!!!!!!!</p>
<p>How do you include an update statement in a case statement xmlDocument&#8230;&#8230;.<br />
eg.</p>
<p>CASE WHEN (@xml.exist(&#8216;/ROOT/Trip/RouteItem[@RouteDBId="875077"]&#8216;)) THEN<br />
UPDATE route_details<br />
	SET<br />
		route_details.trip_authority_code = XMLRouteDetails.TripAuthorityNumber,<br />
		route_details.start_route_location_name = XMLRouteDetails.StartLocationName,<br />
		route_details.Start_Date = XMLRouteDetails.StartDate</p>
<p>From OpenXml(@intPointer,&#8217;/ROOT/Trip/RouteItem&#8217;,3)<br />
	With<br />
	(<br />
		TripAuthorityNumber int &#8216;../@TripAuthorityNumber&#8217;,<br />
		StartLocationName varchar(100),<br />
		StartDate smalldatetime<br />
XMLRouteDetails WHERE route_details.trip_authority_code = XMLRouteDetails.TripAuthorityNumber</p>
<p>	&#8211; Rollback the transaction if there were any errors<br />
	IF @@ERROR  0<br />
	 BEGIN<br />
		&#8211; Rollback the transaction<br />
		ROLLBACK</p>
<p>		&#8211; Raise an error and return<br />
		RAISERROR (&#8216;Error in updating route in route_details table&#8217;, 16, 1)<br />
		RETURN<br />
	 END</p>
<p>	ELSE</p>
<p>	INSERT INTO route_details<br />
	(<br />
		trip_authority_code,<br />
		start_route_location_name,<br />
		Start_Date<br />
)</p>
<p>	Select<br />
		@TripID,<br />
		StartLocationName,<br />
		StartDate<br />
from OpenXml(@intPointer,&#8217;/ROOT/Trip/RouteItem&#8217;,3)<br />
	With<br />
	(<br />
		TripAuthorityNumber int &#8216;../@TripAuthorityNumber&#8217;,<br />
		StartLocationName varchar(100),<br />
		StartDate smalldatetime<br />
)<br />
	&#8211; Rollback the transaction if there were any errors<br />
	IF @@ERROR  0<br />
	 BEGIN<br />
		&#8211; Rollback the transaction<br />
		ROLLBACK</p>
<p>		&#8211; Raise an error and return<br />
		RAISERROR (&#8216;Error in inserting route into route_details table&#8217;, 16, 1)<br />
		RETURN<br />
	 END<br />
	END<br />
	COMMIT<br />
	exec sp_xml_removedocument @intPointer</p>
<p>RETURN</p>
]]></content:encoded>
	</item>
</channel>
</rss>
