Solved

Declare variable in Microsoft SQL Server Management Studio

Posted on 2008-10-28
3
3,261 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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.

832 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