Solved

Declare variable in Microsoft SQL Server Management Studio

Posted on 2008-10-28
3
3,359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql server connection string in config file 4 41
SQL Convert rows to columns 5 34
SQL: get ride of blank rows 11 24
Need split for SQL data 7 50
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

752 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