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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 why my if conditions are failing?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

aakcse
Aged Yak Warrior

India
570 Posts

Posted - 08/31/2012 :  15:20:25  Show Profile  Reply with Quote
The below code is giving me o/p, ideally it should print TEST3 for Nolump & Nolump values for the col variables


NoLump
NoLump
NULL




BEGIN TRY

DECLARE @Col_etc_security_user VARCHAR(100)
DECLARE @Col_User_mask VARCHAR(100)
DECLARE @msg VARCHAR(500)
DECLARE @SQLString VARCHAR(max)

SELECT @Col_etc_security_user = column_name
FROM INFORMATION_SCHEMA.COLUMNS WHERE  table_name = 'Normalized_etc_security_user' and column_name ='LUMP'

SELECT @Col_User_mask = column_name
FROM INFORMATION_SCHEMA.COLUMNS WHERE  table_name = 'NormalizedUser_mask' and column_name ='LUMP'

SELECT isnull(@Col_etc_security_user,'NoLump')
SELECT isnull(@Col_User_mask,'NoLump')

IF (@Col_etc_security_user = 'lump' AND @Col_User_mask='lump')
BEGIN
  SET @msg=  'Files ''user_mask.txt and /etc/security/user''  does not exist.'
  RAISERROR( @msg,11,1)
END

IF (@Col_etc_security_user = 'Nolump' AND @Col_User_mask = 'lump')
BEGIN
	SET @SQLString ='TEST1'
END

IF (@Col_etc_security_user = 'lump' AND @Col_User_mask = 'Nolump')
BEGIN
	SET @SQLString ='TEST2'
END

IF (@Col_etc_security_user = 'Nolump' AND @Col_User_mask = 'Nolump')
BEGIN
	SET @SQLString ='TEST3'
END

SELECT (@SQLString)

END TRY
BEGIN CATCH
 SELECT ERROR_MESSAGE() AS [User name per /etc/security/user],'' AS [Umask per /etc/security/user],'' AS [user name per .profile],'' AS [Umask Per .Profile],'' AS [Word Writable],'' AS [Testing Attribute A],'' AS [Testing Attribute B]  
END CATCH


-Neil

lionofdezert
Aged Yak Warrior

Pakistan
885 Posts

Posted - 08/31/2012 :  15:27:21  Show Profile  Visit lionofdezert's Homepage  Send lionofdezert a Yahoo! Message  Reply with Quote
BEGIN TRY

DECLARE @Col_etc_security_user VARCHAR(100)
DECLARE @Col_User_mask VARCHAR(100)
DECLARE @msg VARCHAR(500)
DECLARE @SQLString VARCHAR(max)

SELECT @Col_etc_security_user = column_name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'Normalized_etc_security_user'
and column_name = 'LUMP'

SELECT @Col_User_mask = column_name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'NormalizedUser_mask'
and column_name = 'LUMP'

SELECT @Col_etc_security_user = isnull(@Col_etc_security_user, 'NoLump')
SELECT @Col_User_mask = isnull(@Col_User_mask, 'NoLump')

IF ( @Col_etc_security_user = 'lump'
AND @Col_User_mask = 'lump'
)
BEGIN
SET @msg = 'Files ''user_mask.txt and /etc/security/user'' does not exist.'
RAISERROR ( @msg, 11, 1 )
END

IF ( @Col_etc_security_user = 'Nolump'
AND @Col_User_mask = 'lump'
)
BEGIN
SET @SQLString = 'TEST1'
END

IF ( @Col_etc_security_user = 'lump'
AND @Col_User_mask = 'Nolump'
)
BEGIN
SET @SQLString = 'TEST2'
END

IF ( @Col_etc_security_user = 'Nolump'
AND @Col_User_mask = 'Nolump'
)
BEGIN
SET @SQLString = 'TEST3'
END

SELECT ( @SQLString )

END TRY
BEGIN CATCH
SELECT ERROR_MESSAGE() AS [User name per /etc/security/user],
'' AS [Umask per /etc/security/user],
'' AS [user name per .profile],
'' AS [Umask Per .Profile],
'' AS [Word Writable],
'' AS [Testing Attribute A],
'' AS [Testing Attribute B]
END CATCH

--------------------------
http://connectsql.blogspot.com/

Edited by - lionofdezert on 08/31/2012 15:28:18
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 08/31/2012 :  15:32:16  Show Profile  Reply with Quote
quote:
Originally posted by aakcse

The below code is giving me o/p, ideally it should print TEST3 for Nolump & Nolump values for the col variables


NoLump
NoLump
NULL




BEGIN TRY

DECLARE @Col_etc_security_user VARCHAR(100)
DECLARE @Col_User_mask VARCHAR(100)
DECLARE @msg VARCHAR(500)
DECLARE @SQLString VARCHAR(max)

SELECT @Col_etc_security_user = column_name
FROM INFORMATION_SCHEMA.COLUMNS WHERE  table_name = 'Normalized_etc_security_user' and column_name ='LUMP'

SELECT @Col_User_mask = column_name
FROM INFORMATION_SCHEMA.COLUMNS WHERE  table_name = 'NormalizedUser_mask' and column_name ='LUMP'

SELECT @Col_etc_security_user =isnull(@Col_etc_security_user,'NoLump')
SELECT @Col_User_mask =isnull(@Col_User_mask,'NoLump')

IF (@Col_etc_security_user = 'lump' AND @Col_User_mask='lump')
BEGIN
  SET @msg=  'Files ''user_mask.txt and /etc/security/user''  does not exist.'
  RAISERROR( @msg,11,1)
END

SET @SQLString=
CASE WHEN (@Col_etc_security_user = 'Nolump' AND @Col_User_mask = 'lump')
THEN	 'TEST1'
WHEN (@Col_etc_security_user = 'lump' AND @Col_User_mask = 'Nolump')
THEN 'TEST2'
WHEN (@Col_etc_security_user = 'Nolump' AND @Col_User_mask = 'Nolump')
THEN 'TEST3'
END

SELECT (@SQLString)

END TRY
BEGIN CATCH
 SELECT ERROR_MESSAGE() AS [User name per /etc/security/user],'' AS [Umask per /etc/security/user],'' AS [user name per .profile],'' AS [Umask Per .Profile],'' AS [Word Writable],'' AS [Testing Attribute A],'' AS [Testing Attribute B]  
END CATCH


-Neil


i dont know why you've exec statement there as it doesnt make any sense to me

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

aakcse
Aged Yak Warrior

India
570 Posts

Posted - 08/31/2012 :  15:33:59  Show Profile  Reply with Quote
Thanks,

I tried this but still I am not able to print 'TEST3' still it say NULL :(

-Neil
Go to Top of Page

aakcse
Aged Yak Warrior

India
570 Posts

Posted - 08/31/2012 :  15:38:02  Show Profile  Reply with Quote
Hi,

I tried after adding the below code but still it is giving NULL and not TEST3

as the @Col_etc_security_user and @Col_User_mask will be NULL after executing the 2 select stm from information schema

then I assigned nolump by correcting as you said


SET @SQLString=
CASE WHEN (@Col_etc_security_user = 'Nolump' AND @Col_User_mask = 'lump')
THEN	 'TEST1'
WHEN (@Col_etc_security_user = 'lump' AND @Col_User_mask = 'Nolump')
THEN 'TEST2'
WHEN (@Col_etc_security_user = 'Nolump' AND @Col_User_mask = 'Nolump')
THEN 'TEST3'
END



-Neil

Edited by - aakcse on 08/31/2012 15:39:53
Go to Top of Page

aakcse
Aged Yak Warrior

India
570 Posts

Posted - 08/31/2012 :  15:50:30  Show Profile  Reply with Quote
Hi Visakh,
Which exec statement?

-Neil
Go to Top of Page

aakcse
Aged Yak Warrior

India
570 Posts

Posted - 08/31/2012 :  16:11:41  Show Profile  Reply with Quote
Thanks I am able to get the result now, I made a mistake at the below statements, I am getting test3 after correcting ...

SELECT @Col_etc_security_user =isnull(@Col_etc_security_user,'NoLump')
SELECT @Col_User_mask =isnull(@Col_User_mask,'NoLump')



-Neil
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.09 seconds. Powered By: Snitz Forums 2000