all groups > sql server programming > august 2004 >
You're in the

sql server programming

group:

select for campare data



Re: select for campare data Keith Kratochvil
8/9/2004 2:14:15 PM
sql server programming: I am confused at your use of <
I would have expected that you use BETWEEN (or > and <).


--
Keith


[quoted text, click to view]
select for campare data pierca
8/9/2004 9:04:12 PM
Hi All

i have a select statement like this

select pro_name, pro_sales, date_sales from inventory
where date_sales < '01/01/2004 ' and date_sales < '03/31/2004'

now i need to select another period to compare data

select pro_name, pro_sales, date_sales from inventory
where date_sales < '01/01/2004 ' and date_sales < '03/31/2004'


how can i build the query to get out this result?

pro_name pro_sales_2003 pro_sales_2004
-----------------------------------------------

thanks
Pierca

Re: select for campare data pierca
8/9/2004 11:26:02 PM
Yes i made mistake

where date_sales > '01/01/2004 ' and date_sales < '03/31/2004'


"Keith Kratochvil" <sqlguy.back2u@comcast.net> ha scritto nel messaggio
news:e7CMkUkfEHA.1644@tk2msftngp13.phx.gbl...
[quoted text, click to view]

Re: select for campare data Roji. P. Thomas
8/10/2004 1:04:04 AM
[quoted text, click to view]

This condition doesnt make sense at all.
any date_sales thats less than '01/01/2004 '
is also less than '03/31/2004'. So the second part of
the where clause is unnecessary.

I guess you havent explained your problem well.
But a wild guess is that you are trying to get a pivot-ed report

If thats the case,You can try something like

SELECT Prod_name,
CASE WHEN Year(date_sale) = 2003 THEN pro_sales END As pro_sales_2003 ,
CASE WHEN Year(date_sale) = 2004 THEN pro_sales END As pro_sales_2004
FROM YourTable

--
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com


[quoted text, click to view]

AddThis Social Bookmark Button