 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
D Whaley Guest
|
Posted: Wed Sep 17, 2003 7:21 pm Post subject: SQL Server Query Question |
|
|
Is it possible to use a variable as part of a query in a Stored Procedure?
Kind of like this (this obviously doesn't work)
CREATE PROCEDURE [Report_ServActSumm] (@SDate as SmallDateTime, @eDate as
SmallDateTime) AS
Declare @MyVar as VarChar(50)
Set MyVar = 'Where ([Date] >= @sDate) AND ([Date] <= @eDate)'
SELECT Description, Sum(Amount)
FROM Expense
@MyVar
GROUP BY Description
GO
|
|
| Back to top |
|
 |
Ignacio Vazquez Guest
|
Posted: Wed Sep 17, 2003 7:32 pm Post subject: Re: SQL Server Query Question |
|
|
"D Whaley" <dwhaley (AT) hs-technologies (DOT) com> wrote in message
[email]3f68b424 (AT) newsgroups (DOT) borland.com[/email]...
| Quote: | Is it possible to use a variable as part of a query in a Stored Procedure?
|
Look up the second form of EXECUTE in the Books Online.
Cheers,
Ignacio
--
No, don't send me e-mail directly. No, just don't.
|
|
| Back to top |
|
 |
Ross Guest
|
Posted: Wed Sep 17, 2003 8:29 pm Post subject: Re: SQL Server Query Question |
|
|
D Whaley wrote:
| Quote: | Is it possible to use a variable as part of a query in a Stored Procedure?
Kind of like this (this obviously doesn't work)
CREATE PROCEDURE [Report_ServActSumm] (@SDate as SmallDateTime, @eDate as
SmallDateTime) AS
Declare @MyVar as VarChar(50)
Set MyVar = 'Where ([Date] >= @sDate) AND ([Date] <= @eDate)'
SELECT Description, Sum(Amount)
FROM Expense
@MyVar
GROUP BY Description
GO
An article at SQLServerCentral.com. You might need to register but if |
you use MS SQL Server and have not used this site you should.
http://www.sqlservercentral.com/columnists/rmarda/howtobuilddynamicstoredprocedures.asp
or
http://tinyurl.com/nq89
Ross
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|