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
Solved

Declare variable in Microsoft SQL Server Management Studio

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
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.

839 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