Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 If statment
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kwacz23
Starting Member

44 Posts

Posted - 08/12/2013 :  09:44:24  Show Profile  Reply with Quote
Hi

I would like to add one more condition in below query. This highlighted part is not working. Could you help me with that ?

@Country nvarchar(10)

IF (@Country = 'ES' OR @Country = 'PT')
SELECT 'Win 7 64 bit'
IF (country ='FR')
select 'win test'

ELSE
SELECT 'Win 7 32 bit'
UNION
SELECT 'Win 7 64 bit'

MuMu88
Aged Yak Warrior

549 Posts

Posted - 08/12/2013 :  10:14:12  Show Profile  Reply with Quote
I am not sure about the logic, but here is how you can fix the syntax:


IF (@Country = 'ES' OR @Country = 'PT')
SELECT 'Win 7 64 bit'
ELSE
IF (@country ='FR')
select 'win test'
ELSE
SELECT 'Win 7 32 bit'
UNION
SELECT 'Win 7 64 bit'

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30421 Posts

Posted - 08/12/2013 :  10:15:06  Show Profile  Visit SwePeso's Homepage  Reply with Quote
IF (@country ='FR')


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

ScottPletcher
Aged Yak Warrior

USA
550 Posts

Posted - 08/12/2013 :  14:38:07  Show Profile  Reply with Quote
To me, this style is easier to code, follow and, esp. maintain:



SELECT
    CASE WHEN @Country IN (N'ES', N'PT') 
         THEN 'Win 7 64 bit'
         WHEN @country IN (N'FR')
         THEN 'win test'
         ELSE 'Win 7 32 bit'
    END AS Win_Version

Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2241 Posts

Posted - 08/13/2013 :  00:26:32  Show Profile  Reply with Quote
DECLARE @Country varchar(10) = 'India'
SELECT
    CASE WHEN @Country IN (N'ES', N'PT') 
         THEN 'Win 7 64 bit'
         WHEN @country IN (N'FR')
         THEN 'win test'
         ELSE 'Win 7 32 bit, Win 7 64 bit'
    END AS Win_Version

If you wish to use  IF...ELSE statement only, then follow MuMu88's post
DECLARE @Country varchar(10) = 'India'
IF (@Country in ( 'ES', 'PT'))
   SELECT 'Win 7 64 bit'
ELSE IF (@country ='FR')
   SELECT 'win test'
ELSE
   SELECT 'Win 7 32 bit'
     UNION
    SELECT 'Win 7 64 bit'

--
Chandu

Edited by - bandi on 08/13/2013 00:27:32
Go to Top of Page

kwacz23
Starting Member

44 Posts

Posted - 08/14/2013 :  04:19:01  Show Profile  Reply with Quote
Thanks
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2241 Posts

Posted - 08/14/2013 :  08:04:56  Show Profile  Reply with Quote
quote:
Originally posted by kwacz23

Thanks


welcome

--
Chandu
Go to Top of Page

sivadss2007
Starting Member

India
18 Posts

Posted - 08/28/2013 :  09:04:24  Show Profile  Reply with Quote
@Country nvarchar(10)

IF (@Country = 'ES' OR @Country = 'PT')
SELECT 'Win 7 64 bit'
IF (@country ='FR')
select 'win test'
ELSE
SELECT 'Win 7 32 bit'
UNION
SELECT 'Win 7 64 bit'

P.Siva
Go to Top of Page

ShivaKrishna
Starting Member

India
20 Posts

Posted - 08/28/2013 :  09:54:22  Show Profile  Reply with Quote
SELECT
CASE WHEN @Country IN ('ES', 'PT')
THEN 'Win 7 64 bit'
WHEN @country ='FR'
THEN 'win test'
ELSE 'Win 7 32 bit'
END AS Win_Version
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000