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
 General SQL Server Forums
 New to SQL Server Programming
 Declaring variables properly

Author  Topic 

tigerweld
Starting Member

12 Posts

Posted - 2011-06-01 : 09:37:12
I'm having trouble understanding all the different ways relating declaring variables in SQL. (MS SQL 2005) How can I declare the date1 and date2 variables?


date1 = DateAdd("d",0,Date) & " 00:00:00.000"
date2 = DateAdd("d",1,Date) & " 00:00:00.000"


Select
DDA,
SiteID,
TimeTransmitted,
RIGHT('0000000000'+ convert(varchar(10),convert(int,DepositTotal*100)),10)
From Deposits Where Deposits.CustomerID = '132'
And convert(varchar(10),Deposits.TimeTransmitted,121)
Between date1 AND date2

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-06-01 : 09:42:36
Are you doing this in t-SQL or using a front-end app? If you want date1 and date2 to be dates, you need to declare them as such.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

tigerweld
Starting Member

12 Posts

Posted - 2011-06-01 : 11:48:44
From the Server Management Studio Console.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-06-01 : 11:58:36
I'm assuming that Date means today's date.

DECLARE @date1 datetime
DECLARE @date2 datetime

SET @date1 = dateadd(day,datediff(day,0,getdate()),0)
SET @date2 = dateadd(day,datediff(day,-1,getdate()),0)

you shouldn't need to convert TimeTransmitted anymore.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -