Reputation: 1564
I want if col1_list is not null or not empty or if col2_list is not null or not empty do some logic and set rc = 0, else set rc = 1 . If some of col_list is null or empty set rc 1 . But logical OR operator not work in if statement or what I'm doing wrong ?
declare @col1_list varchar(max) , @col2_list varchar(max)
declare @tbl TABLE (col1 int , col2 int)
declare @rc char(1) = '0'
set @col1_list = '2|6|7|8|'
set @col2_list = '1|'
IF (@col1_list IS NOT NULL OR @col1_list <> '' OR @col2_list IS NOT NULL OR @col2_list <> '')
BEGIN
DECLARE @myXML1 AS XML = N'<H><r>' + REPLACE(@col1_list, '|', '</r><r>') + '</r></H>'
DECLARE @myXML2 AS XML = N'<H><r>' + REPLACE(@col2_list, '|', '</r><r>') + '</r></H>';
with mycte as (SELECT Vals1.id.value('.', 'NVARCHAR(50)') AS val1
FROM @myXML1.nodes('/H/r') AS Vals1(id)),
mycte1 as (SELECT Vals2.id.value('.', 'NVARCHAR(50)') AS val2
FROM @myXML2.nodes('/H/r') AS Vals2(id))
insert into @tbl (col1,col2)
select val1,val2
from mycte,mycte1
where val1 <> '' and val2 <> ''
set @rc = '0'
END
ELSE
set @rc ='1'
select @rc as [rc]
Have Rc = 0 when some of col_list is null or empty
Upvotes: 0
Views: 239
Reputation: 21757
Try changing your if condition to this:
IF (NOT(@col1_list IS NULL OR @col1_list = '') AND NOT(@col2_list IS NULL OR @col2_list = ''))
This one checks 2 things:
@col1_list
is neither null nor empty, AND@col2_list
is neither null nor empty.Upvotes: 1