Groups | Blog | Home
all groups > sql server mseq > october 2003 >

sql server mseq : Help with query . . . ..


Newbie
10/21/2003 3:39:32 PM
Hi

I have a parameter @Status in a stored procedure

How can I achieve the following

a). return all records or
b) return only records that are = 'N' or null or blank

I thought about
where compflag = coalesce(@status,compflag)

but this doesn't cater for both 'N' and null records

what do you suggest I should do?

Newbie
10/21/2003 4:35:35 PM
Thanks but I am not sure I understand what you mean . . :-(
I call this stored procedure from vb

What I am trying to achieve is the following:
compflag has 4 possible values:
'Y', 'N', null, blank

I want to be able to return either
a) all records i.e 'Y', 'N', null, blank or,
b) records that = 'N', null or blank

all from one query if possible

what do I need to do?

Thanks again for your help



[quoted text, click to view]

Newbie
10/21/2003 5:03:21 PM

table 1
PONo
LineNum
CompFlag
Stockcode

Record 1
PONo:R12345
LineNum:1
CompFlag:Y
Stockcode:PartABC

Record 2
PONo: R98765
LineNum: 1
CompFlag: N
Stockcode:PartABC

Record 3
PONo: S34567
LineNum: 1
CompFlag: null
Stockcode: PartHIJ

Record 4
PONo: S34567
LineNum: 2
CompFlag: ''
Stockcode: PartHIJ


On my vb form I have checkbox - incl. completed orders
If this is ticked I want to return all records
i.e Records 1,2,3,4

If it isn't ticked I want to return records 2, 3 and 4 i.e all records
where CompFlag <> 'Y'

[quoted text, click to view]

Vishal Parkar
10/21/2003 8:43:30 PM
Newbie,


[quoted text, click to view]

The above condition will check value of @status if it is not null then it will always return this
value.

You can put condition as

declare @status char(1)
set @status='N'
select * from table
where (col1 = @status or col1 is null or ltrim(col1) = '')


--
- Vishal


Vishal Parkar
10/21/2003 9:10:41 PM
Newbie,
can you post table structure some sample records, whether you are passing any parameter to query and
if yes then on the basis of value from this parameter what records should be retrieved.

--
- Vishal


Vishal Parkar
10/21/2003 10:33:00 PM
Newbie,
See following example


create table #t(PONo varchar(25),LineNum varchar(25),CompFlag char(1),Stockcode varchar(50))

insert into #t
select 'R12345',1,'Y','PartABC' union all
select 'R98765', 1, 'N','PartABC' union all
select 'S34567', 1, null,'PartHIJ' union all
select 'S34567', 2, '','PartHIJ'

--Required script would be.

declare @checked char(1)
set @checked='Y' --if checkebox is checked pass a variable value as 'Y' to query
if @checked = 'Y'
select * from #t
Else
select * from #t where (compflag <> 'Y' or compflag is null)

--
- Vishal


Newbie
10/22/2003 12:54:01 PM

thanks - works a treat
Al


[quoted text, click to view]

AddThis Social Bookmark Button