all groups > sql server programming > april 2007 >
You're in the

sql server programming

group:

Query based on date?


Query based on date? jtglock
4/11/2007 7:43:44 PM
sql server programming:
I have a table that contains the following fields Startdate, Enddate,
and Amount. The Startdate is always 7 days prior to the Enddate.
What I am looking to do is specify the Enddate which returns an amount
but then in another view have the Enddate be 7 days prior to the
Enddate specfied in the first view which will then return a different
Amount. Is there a way to do this? Thanks in advance for the help.
Re: Query based on date? xyb
4/11/2007 8:03:27 PM
On 4=D4=C212=C8=D5, =C9=CF=CE=E710=CA=B143=B7=D6, "jtglock" <jtwen...@gmail=
[quoted text, click to view]
you may need always post your DDL and specify what results you would
want to achieve:)
if i have not misuderstood your meaning,
you can use union select.
try
select startdate,endate,amount from view1 where Enddate =3D @paraDate
union select startdate,endate,amount from view2 where Enddate =3D
dateadd(day,@paraDate,-7)
Re: Query based on date? M A Srinivas
4/11/2007 10:03:03 PM
[quoted text, click to view]

Post is not clear. Views will not accept parameters , Stored Procedure
can do .
If you want to go for the view route , Create a Permanent table Insert
these parameters values ( may be with some flags for current day and
previous 7 day ) , and in the view
join in this table to get the result
Re: Query based on date? jtglock
4/12/2007 8:37:05 AM

[quoted text, click to view]


I guess I would need to do this in a stored procedure how would I go
about doing this? I am sorry for all the questions but I am new to
this.
Re: Query based on date? --CELKO--
4/12/2007 12:09:02 PM
[quoted text, click to view]

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. 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.

Rows are not records; fields are not columns; tables are not files;
You have never programmed SQL before, have you?

[quoted text, click to view]

If you had the Netiquette, we would see this constraint in the DDL.

[quoted text, click to view]

unh? Read that spec and see if you have any idea what it means!!

I am guessing that you want to see a two-week window but not in one
VIEW. I am going to assume that want the amount of the weight in
kilograms of bagpipes since your data element names were so useless.

Please learn to write a spec if you are going to stay in the IT
trade. This is FAR MORE FUNDAMENTAL than SQL.


AddThis Social Bookmark Button