July 8, 2010 at 12:29 am
Hi everyone..
I have a query that gets the 30 days back information information
for example:select * from table name where date=getdate-30
I want to pass the valu dynamically place of 30.how to solve this can any one give the solution
Regards ..
Anil...
Regards..
guru12
July 8, 2010 at 4:34 am
may be it helps you :
declare @value int
declare @sql varchar(200)
set @sql= 'select * from tablename where date=getdate()-'+@value+
exec(@sql)
Hi everyone..
I have a query that gets the 30 days back information information
for example:select * from table name where date=getdate-30
I want to pass the valu dynamically place of 30.how to solve this can any one give the solution
Regards ..
Anil...
July 8, 2010 at 4:47 am
Use a variable for your value of -30.
Employ the function DATEADD()
Take great care with DATETIME data types with regard to the time portion.
Ignore pointless recommendations to use dynamic SQL.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply