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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 If statment

Author  Topic 

kwacz23
Starting Member

44 Posts

Posted - 2013-08-12 : 09:44:24
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 - 2013-08-12 : 10:14:12
I am not sure about the logic, but here is how you can fix the syntax:
[CODE]

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'

[/CODE]
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-08-12 : 10:15:06
IF (@country ='FR')


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

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2013-08-12 : 14:38:07
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-08-13 : 00:26:32
[code]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'
[/code]
--
Chandu
Go to Top of Page

kwacz23
Starting Member

44 Posts

Posted - 2013-08-14 : 04:19:01
Thanks
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-08-14 : 08:04:56
quote:
Originally posted by kwacz23

Thanks


welcome

--
Chandu
Go to Top of Page

sivadss2007
Starting Member

18 Posts

Posted - 2013-08-28 : 09:04:24
@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

20 Posts

Posted - 2013-08-28 : 09:54:22
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
   

- Advertisement -