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

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

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