BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SQL Server Query Question

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
D Whaley
Guest





PostPosted: Wed Sep 17, 2003 7:21 pm    Post subject: SQL Server Query Question Reply with 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


Back to top
Ignacio Vazquez
Guest





PostPosted: Wed Sep 17, 2003 7:32 pm    Post subject: Re: SQL Server Query Question Reply with quote



"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





PostPosted: Wed Sep 17, 2003 8:29 pm    Post subject: Re: SQL Server Query Question Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.