Link to home
Start Free TrialLog in
Avatar of bibi92
bibi92Flag for France

asked on

adding parameters to a query

Hello,

How can I modify this query for adding date and hours in parameters ? :

select a.[In #]
,b.[Urgency ID:]
      ,a.[Sequence]
      ,a.[Date]
      ,a.[From Group:]
      ,a.[To Group:]
      ,a.[Action ID]
      ,a.[Login ID]
from _SM_.[Inc Details] a,_SM_.Inc b
where [Date] <= (DATEADD(hh,19, DATEADD(dd, DATEDIFF(dd,0,GETDATE())-1, 0)))
and [Date] >=   (DATEADD(hh, 1, DATEADD(dd, DATEDIFF(dd,0,GETDATE())-1, 0))) 

Open in new window


Thanks

Regards
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try look for DatePart function

ref:
DATEPART (Transact-SQL)
https://msdn.microsoft.com/en-us/library/ms174420.aspx
To add hour comparison, try like:
...
and DATEPART(hour, [yourDatefield] ) = <value> 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
#s do not force brackets to be used around column names, it is the space forcing that.  "In#" would be a perfectly valid column name.