﻿<?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 Newbies  / Help writing query 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>Mon, 17 Jun 2013 23:41:43 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Help writing query logic</title><link>http://www.sqlservercentral.com/Forums/Topic1038524-1292-1.aspx</link><description>[quote][b]stevenplee (12/23/2010)[/b][hr]Thanks,  For your response.   What does the ":with cte AS" statement do?[/quote]A whole lot.  Take a look at "WITH common_table_expression" in Books Online... there's just too much info to post here.</description><pubDate>Thu, 23 Dec 2010 18:43:51 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Help writing query logic</title><link>http://www.sqlservercentral.com/Forums/Topic1038524-1292-1.aspx</link><description>Thanks,  For your response.   What does the ":with cte AS" statement do?Thanks I'll give this a try</description><pubDate>Thu, 23 Dec 2010 17:41:43 GMT</pubDate><dc:creator>stevenplee</dc:creator></item><item><title>RE: Help writing query logic</title><link>http://www.sqlservercentral.com/Forums/Topic1038524-1292-1.aspx</link><description>Something like this?[code="sql"]DECLARE @tbl TABLE( DATE DATETIME, OrderNmbr INT, Transtype VARCHAR(10), Amount INT, InvoiceinPer CHAR(1))--/*INSERT INTO @tblSELECT '12/1/2010', 12345 ,'Inv', 1000 ,'N' UNION ALLSELECT '12/3/2010', 12345 ,'Credit', -1000 ,'N' UNION ALLSELECT '12/3/2010', 12345 ,'Rebill', 2000 ,'N'--*//*insert into @tblselect '12/1/2010', 12345 ,'Inv', 1000 ,'N' union allselect '12/1/2010', 12345 ,'Credit', -1000 ,'N' union allselect '12/1/2010', 12345 ,'Rebill', 2000 ,'N'*/;WITH cte AS(	SELECT TOP 1 DATE FROM @tbl t ORDER BY DATE)UPDATE @tbl SET InvoiceinPer='Y'FROM @tbl tINNER JOIN cte ON t.date = cte.dateSELECT  *FROM    @tbl[/code]</description><pubDate>Thu, 23 Dec 2010 10:25:41 GMT</pubDate><dc:creator>LutzM</dc:creator></item><item><title>Help writing query logic</title><link>http://www.sqlservercentral.com/Forums/Topic1038524-1292-1.aspx</link><description>I need a little help figuring out this logic.  I need to write a query that will set the Field InvoiceinPer value to Y if the order# is the same and the date is the same regardless to the transType. (see example1)Example2 Will set the invoiceinper value to Y only if the transtype is anything other than Credit or rebill and the dates are different.   Suggestion would be appreciated.Ex1Date	            Order#  Transtype	Amount	InvoiceinPer12/1/2010	12345	Inv	1000	Y12/1/2010	12345	Credit	-1000	Y12/1/2010	12345	Rebill	2000	YEx2				Date	            Order#  Transtype	Amount	InvoiceinPer12/1/2010	12345	Inv	1000	Y12/3/2010	12345	Credit	-1000	N12/3/2010	12345	Rebill	2000	N</description><pubDate>Wed, 22 Dec 2010 15:07:59 GMT</pubDate><dc:creator>stevenplee</dc:creator></item></channel></rss>