Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Variables


Message #1 by "Carolyn Friedberg" <cfriedberg@c...> on Mon, 12 Aug 2002 16:54:26
Do this for the last couple of lines
GETDATE(), SYSTEM_USER
FROM dbo.TempBil
WHERE  
  (dbo.TempBil.BDATE >=3D CONVERT(DATETIME, @BeginDate, 102)) AND
(dbo.TempBil.BDATE <=3D CONVERT(DATETIME, @EndDate, 102))
AND dbo.TempBil.BECODE =3D 'N' + Char(39) + @Emp1

This should work,  test it out


-----Original Message-----
From: Carolyn Friedberg [mailto:cfriedberg@c...]
Sent: Monday, August 12, 2002 12:54 PM
To: sql language
Subject: [sql_language] Variables

I have the following code:

Declare @BeginDate as datetime, @EndDate as datetime
Declare @Emp1 as varchar(10)
Declare @Emp2 as varchar(10)
Declare @Emp3 as varchar(10)

Declare @EmpWhere as varchar(750)

Set @Emp1 =3D 3109
Set @Emp2 =3D 4620
Set @Emp3 =3D 4643

Set @EmpWhere =3D " dbo.TempBil.BECODE =3D N" + Char(39) + @Emp1
Set @BeginDate =3D '2001-01-01'
Set @EndDate =3D'2001-12-31'
SELECT DISTINCT
dbo.TempBil.BECODE,
DATEPART(wk, dbo.TempBil.BDATE),
DATEPART(yy, dbo.TempBil.BDATE)

GETDATE(), SYSTEM_USER
FROM dbo.TempBil
WHERE  
  (dbo.TempBil.BDATE >=3D CONVERT(DATETIME, @BeginDate, 102)) AND
(dbo.TempBil.BDATE <=3D CONVERT(DATETIME, @EndDate, 102))
AND @EmpWhere

When I try to execute it, I get an error with regard to the  @EmpWhere.

I want to build this part of the select statement based on the number of

@Emp's I may have.

Why is this not working?

Carolyn

  Return to Index