﻿<?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  / COMPARE QUERY / 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>Sat, 25 May 2013 16:29:48 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: COMPARE QUERY</title><link>http://www.sqlservercentral.com/Forums/Topic1008383-391-1.aspx</link><description>possibly thanks ill have to see</description><pubDate>Fri, 22 Oct 2010 09:30:28 GMT</pubDate><dc:creator>sharonmtowler</dc:creator></item><item><title>RE: COMPARE QUERY</title><link>http://www.sqlservercentral.com/Forums/Topic1008383-391-1.aspx</link><description>Sharon,You are asking two separate questions here:" is there a way to compare the next record in the query to the previous record"and"i would like to see if there is a different unit cost on a sku as long as it is the same season, style and color  "Andrew and Celko have responded to your first question by trying to make it a teachable moment about set-based thinking.   SQL does not guarantee any order of records unless you tell it an order.  Your order by clause is less than the fields driving your groups, so within a group, "next record" cannot be predicted.  In the provided query, "next record" is an ambiguous concept unless you can articulate what it means to be the next record.  Now, your initial idea of using "next record" as what you think you need to solve the business question can eventually get the answer with further elaboration that would allow the data in one record to determine what the "next record" would be, but really it doesn't need it.  An answer with this approach is subject to misinterpretation and a more complicated than necessary query.      "i would like to see if there is a different unit cost on a sku as long as it is the same season, style and color  "Does this answer the business question:SELECT SCDIVN AS COMPANY, SCSEAS AS SEASON, SCSTYL AS STYLE, SCCOLR AS COLOR, SCSKU# AS SKU, Min(sccost) as lowestcost,Max(sccost) as highestcostFROM dbo.SHIPSKU#WHERE (SCDIVN = 'aaa')GROUP BY SCDIVN, SCSEAS, SCSTYL, SCCOLR, SCSKU# Having Min(sccost) &amp;lt;&amp;gt; Max(sccost)</description><pubDate>Fri, 22 Oct 2010 09:20:56 GMT</pubDate><dc:creator>keith.gerritsen</dc:creator></item><item><title>RE: COMPARE QUERY</title><link>http://www.sqlservercentral.com/Forums/Topic1008383-391-1.aspx</link><description>never mind ill figure it out. this was just a quick query that i posted to see if someone had any suggestions on a creating a compare query. didnt need code debugged or anything of that nature. thanks anyway</description><pubDate>Fri, 22 Oct 2010 07:33:31 GMT</pubDate><dc:creator>sharonmtowler</dc:creator></item><item><title>RE: COMPARE QUERY</title><link>http://www.sqlservercentral.com/Forums/Topic1008383-391-1.aspx</link><description>This makes no sense. Rows are not records; there is no ordering unless you EXPLICITLY show it as values in a column. Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Please learn to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. Sample data is also a good idea, along with clear specifications. It is very hard to debug code when you do not let us see it. If you want to learn how to ask a question on a Newsgroup, look at: http://www.catb.org/~esr/faqs/smart-questions.html </description><pubDate>Thu, 21 Oct 2010 13:07:13 GMT</pubDate><dc:creator>CELKO</dc:creator></item><item><title>RE: COMPARE QUERY</title><link>http://www.sqlservercentral.com/Forums/Topic1008383-391-1.aspx</link><description>You have a GROUP BY clause but since you have no aggregate functions its only effect is to eliminate duplicate rows.i am dividing in the case statement. It would help if you could describe what you trying to do in some more detail, i am trying to compare records in the query. if record 1 says 14.50 i want it to search the next row to see if it has the same valueincluding providing the DDL scripts for the table, and INSERT statements to insert some test data into that table.there are no scripts to the table, no insert statements, this is querying a table for data not inserting into the table </description><pubDate>Thu, 21 Oct 2010 12:00:23 GMT</pubDate><dc:creator>sharonmtowler</dc:creator></item><item><title>RE: COMPARE QUERY</title><link>http://www.sqlservercentral.com/Forums/Topic1008383-391-1.aspx</link><description>You have a GROUP BY clause but since you have no aggregate functions its only effect is to eliminate duplicate rows.It would help if you could describe what you trying to do in some more detail, including providing the DDL scripts for the table, and INSERT statements to insert some test data into that table.</description><pubDate>Thu, 21 Oct 2010 08:23:15 GMT</pubDate><dc:creator>andrewd.smith</dc:creator></item><item><title>RE: COMPARE QUERY</title><link>http://www.sqlservercentral.com/Forums/Topic1008383-391-1.aspx</link><description>Not sure if i understand 100% what you are asking but, i am grouping my query</description><pubDate>Thu, 21 Oct 2010 07:10:59 GMT</pubDate><dc:creator>sharonmtowler</dc:creator></item><item><title>RE: COMPARE QUERY</title><link>http://www.sqlservercentral.com/Forums/Topic1008383-391-1.aspx</link><description>How do you define the sequential order of rows in this table?Is there a suitable datetime column or an incrementing integer column?</description><pubDate>Thu, 21 Oct 2010 06:59:48 GMT</pubDate><dc:creator>andrewd.smith</dc:creator></item><item><title>COMPARE QUERY</title><link>http://www.sqlservercentral.com/Forums/Topic1008383-391-1.aspx</link><description>is there a way to compare the next record in the query to the previous recordi would like to see if there is a different unit cost on a sku as long as it is the same season, style and colorSELECT      SCDIVN AS COMPANY, SCSEAS AS SEASON, SCSTYL AS STYLE, SCCOLR AS COLOR, SCSKU# AS SKU, SCQTY AS QTY, SCCOST AS INV_COST, CASE WHEN scqty = 0 THEN 0 WHEN sccost = 0 THEN 0 ELSE (SCCOST / SCQTY) END AS UNIT_COSTFROM         dbo.SHIPSKU#WHERE     (SCDIVN = 'aaa')GROUP BY SCDIVN, SCSEAS, SCSTYL, SCCOLR, SCSKU#, SCQTY, SCCOSTORDER BY COMPANY, SEASON, STYLE, COLOR</description><pubDate>Thu, 21 Oct 2010 06:25:08 GMT</pubDate><dc:creator>sharonmtowler</dc:creator></item></channel></rss>