Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 stuck in query

Author  Topic 

Sion01
Starting Member

6 Posts

Posted - 2010-05-20 : 10:10:50
hi, im trying to make a query but im stuck
I want to complete an existing query to filter a couple things but i cant seem to get it working.

i have two fields, one with DateUnit and Period, DateUnit contains ('w' (for week), 'm' (for month), etc), and Period the amount.
I wanted to used DATEADD, but the DATEADD will change depending on the value of DateUnit.

I need to complete the query, the ses what is the unit of time and does the aproprieate DATEADD, im using IF, but it just "crashes".

Im going desperate...

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-05-20 : 10:14:42
Show us the query, some sample data and your expected output.
Go to Top of Page

Sion01
Starting Member

6 Posts

Posted - 2010-05-20 : 10:35:55
The result I expect is to get only the record that have date ranges that alredy expired or going to.

The thing is i have a record, and that record has a DateUnit and Period, that are set on the aplication.
For example:
_____
Period 5 DateUnit W(weeks)
Period 1 DateUnit Y(Years)

I want make a query that show only the records whose perior have passes, and for that i use DATEADD, but i need to see if the unit is W or Y for that, and i need some sort of IF, wich im getting the error at...

Example:

___
SELECT Something from Table1
From ....
WHERE condition AND
Cod1 in (this is where i have to put my query)

And in here i need to check the value on DateUnit to use DATEADD (so i can pass the argument, DAY/MONTH/etc)
Go to Top of Page
   

- Advertisement -