Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all .
I want to make selection in my sql query .
SQL
SELEC DATEADD((CASE WHEN table.date_i = '1' or table.date_i = '4' THEN 'day' ELSE 'month' end as col ),  7 , current_timestamp )  < current_timestamp FROM table

I need to add 7 days or 7 months depend on table.datei values . This query doesn't work . Please help me to make this .
MS SQL SERVER T-SQL
Posted

Try:
SQL
SELECT
   CASE WHEN table.date_i = '1' or table.date_i = '4' THEN DATEADD( dd, 7 , current_timestamp)
        ELSE DATEADD( mm, 7 , current_timestamp)
   END AS Col
FROM table


Doubt if it'll be exactly what you want - but your "SQL" is seriously odd, so I can;t work out exactly what you are trying to do...
 
Share this answer
 
v2
You need to make small modifications in the way use define the interval. One possibility is to use structure like the following:
SQL
DECLARE @intervaltype int;
DECLARE @datetouse date

SET @datetouse = GETDATE()
SET @intervaltype = 1;
--SET @intervaltype = 2;

SELECT CASE @intervaltype
          WHEN 1 THEN DATEADD( day, 7, @datetouse)
          WHEN 2 THEN DATEADD( month, 7, @datetouse)
       END

In the real situation you would replace the variable with some columns from some table.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900