Declare variable in Microsoft SQL Server Management Studio

Posted on 2008-10-28
Last Modified: 2010-04-21
Hi all

How can I get this query below to use the variables

Thanks in Advance
@F0_GgAb	datetime,
@F1_GBis	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 @F1_GBis)

Open in new window

Question by:ZURINET
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
LVL 16

Assisted Solution

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)
LVL 17

Accepted Solution

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


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"   ?

Author Closing Comment

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

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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.

623 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