Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Declare variable in Microsoft SQL Server Management Studio

Posted on 2008-10-28
3
Medium Priority
?
3,557 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 800 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 1200 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
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 UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

824 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