Solved

Declare variable in Microsoft SQL Server Management Studio

Posted on 2008-10-28
3
3,201 Views
Last Modified: 2010-04-21
Hi all

How can I get this query below to use the variables
@F0_GgAb
@F1_GBis

Thanks in Advance
DECLARE 

@F0_GgAb	datetime,

	

@F1_GBis	datetime	
 

BEGIN

  SET @F0_GAb = 2008-10-22

  SET @F1_GBis = 2008-10-24

END
 

select * from T00 

WHERE (F20 = 101 AND 

F3 = '00150'  AND

GgAb = @F0_GAb

AND @F1_GBis)

Open in new window

0
Comment
Question by:ZURINET
3 Comments
 
LVL 16

Assisted Solution

by:brad2575
brad2575 earned 200 total points
ID: 22820453
try this:

DECLARE @F0_GgAb as datetime, @F1_GBis  as datetime        
 
SET @F0_GAb = '2008-10-22'
SET @F1_GBis = '2008-10-24'
 
select * from T00
WHERE (F20 = 101 AND
F3 = '00150'  AND
GgAb = @F0_GAb
AND GBis = @F1_GBis)
0
 
LVL 17

Accepted Solution

by:
aflockhart earned 300 total points
ID: 22820491
Your names don't match.

DECLARE    @F0_GgAb
and
SET @F0_GAb

You also need quote marks around the dates '2008-10-22'

also check the SELECT statement - do you mean to use "BETWEEN @F0_GgAb AND @F1_GBis"   ?
0
 

Author Closing Comment

by:ZURINET
ID: 31510674
My error is explained here >>You also need quote marks around the dates '2008-10-22'<<
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now