If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > just query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-20-04, 03:46
rafala rafala is offline
Registered User
 
Join Date: Feb 2004
Location: Poland
Posts: 96
just query

in MsSQL


USE Northwind
GO

SET NOCOUNT ON
CREATE TABLE myTable99( type char(10),[date] datetime, price money
, PRIMARY KEY (type, [date]))
GO

INSERT INTO myTable99(type,[date],price)
SELECT 'bat' ,'1/1/2001',10.00 UNION ALL
SELECT 'bat' ,'1/1/2002',20.00 UNION ALL
SELECT 'bat' ,'1/1/2003',30.00 UNION ALL
SELECT 'bat' ,'1/1/2004',40.00 UNION ALL
SELECT 'ball','1/1/2001',40.00 UNION ALL
SELECT 'ball','1/1/2002',30.00 UNION ALL
SELECT 'ball','1/1/2003',20.00 UNION ALL
SELECT 'ball','1/1/2004',10.00
GO


What I need, is to create view
with the result


type date (date from) price date_to
ball 2001-01-01 40.0000 2001-12-31 (next date -1 day)
ball 2002-01-01 30.0000 2002-12-31
ball 2003-01-01 20.0000 2003-12-31
ball 2004-01-01 10.0000 today
bat 2001-01-01 10.0000 2001-12-31
bat 2002-01-01 20.0000 2002-12-31
bat 2003-01-01 30.0000 2003-12-31
bat 2004-01-01 40.0000 today



it's needed to be able to add new dates, and prices

Help
Reply With Quote
  #2 (permalink)  
Old 09-20-04, 07:01
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
something like this (untested) --
Code:
select type 
     , [date] as date_from
     , price 
     , case when dateadd(dd,-1,dateadd(yy,1,[date]))
                  > getdate() 
            then 'today'
            else convert(char(10),
                 dateadd(dd,-1,dateadd(yy,1,[date]))
                        ,120)  as date_to 
  from yourtable
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-20-04, 11:17
rafala rafala is offline
Registered User
 
Join Date: Feb 2004
Location: Poland
Posts: 96
Thanks but I mean smth. else



type date (date from) price date_to
ball 2001-01-01 40.0000 2001-12-31 (next date -1 day)
ball 2002-01-01 30.0000 2002-12-31
ball 2003-01-01 20.0000 2003-12-31
ball 2004-01-01 10.0000 today
bat 2001-01-01 10.0000 2001-12-31
bat 2002-01-01 20.0000 2002-12-31
bat 2003-01-01 30.0000 2003-12-31
bat 2004-01-01 40.0000 today = getdate()

but i will add the rows to mu table like

bat 2004-05-01 50.0000


so
the result
....
...
bat 2004-01-01 40.0000 2004-04-30 (the next date -1 day)
bat 2004-05-01 50.0000 today = getdate()


some of types will be 2 dates and 2 prices but some of it many.
Reply With Quote
  #4 (permalink)  
Old 09-20-04, 14:27
Brett Kaiser Brett Kaiser is offline
Window Washer
 
Join Date: Nov 2002
Location: Jersey
Posts: 10,303
I remeber this...what the hell does "today" mean in the result set?
__________________
Brett
8-)

It's a Great Day for America everybody!

dbforums Yak CorralRadio 'Rita
dbForums Member List
I'm Good Once as I ever was

The physical order of data in a database has no meaning.
Reply With Quote
  #5 (permalink)  
Old 09-20-04, 14:28
rafala rafala is offline
Registered User
 
Join Date: Feb 2004
Location: Poland
Posts: 96
today is today = getdate()
Reply With Quote
  #6 (permalink)  
Old 09-20-04, 14:32
rafala rafala is offline
Registered User
 
Join Date: Feb 2004
Location: Poland
Posts: 96
in the table are the dates of new prices and the new prices (and type - mean product)

what i need is the periods when the prices is good
the last price is good unles today =getdate()
Reply With Quote
  #7 (permalink)  
Old 09-20-04, 15:10
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
i thought i understood what you wanted but now i don't have a clue

good luck
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On