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
 General SQL Server Forums
 New to SQL Server Programming
 select record in table

Author  Topic 

amirs
Constraint Violating Yak Guru

260 Posts

Posted - 2010-01-12 : 22:37:16
hi
i have following table
tb1
col1 col2 col3 col4
dia pw r
dia pw r r0
dia rw b p0
dia rw b

how to select record to matching a col1='dia' col2='pw' col3='r' col4 is blank or col4= 'r0'

thanks is advance

dattatreysindol
Starting Member

20 Posts

Posted - 2010-01-12 : 22:58:48
Hi There,

Use the following query:

SELECT Col1, Col2, Col3, Col4
FROM tb1
WHERE Col1 = 'dia' OR Col2 = 'pw' OR Col3 = 'r' OR Col4 IN ('','r0')

Based on whether the data is clean or not you can add the LTRIM/RTRIM to the fields in the WHERE clause.

Hope that helps!

Dattatrey Sindol
http://mytechnobook.blogspot.com/

This information is provided "AS IS" with no warranties, and confers no rights.
Go to Top of Page

amirs
Constraint Violating Yak Guru

260 Posts

Posted - 2010-01-12 : 23:37:43
thanks to replay
it is work when one col is null or not null
but i have four col argument to pass where clouse.in four colomn is null or not null. so i have pass the null value or data value
currently i have write following query

col1 col2 col3 col4
dia pw r
dia pw r r0
dia rw b p0
dia rw b

select col1,col2,col3,col4 from tbl
while recordset.eof=false
if col1='dia' or col1='' and col2='pw' or col2=''and col3='r' or col3='' and col4='ro' or col4='' then
msgbox "record found
end if

wend

this code found the 1 and 2 record and it is right.but this is very time consuming process.

so how to write query to check in where clouse null or datavalue in one select query.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-13 : 01:13:38
select col1,col2,col3,col4 from tbl
where (col1='dia' or col1='')
and (col2='pw' or col2='')
and (col3='r' or col3='')
and (col4='ro' or col4='')
Go to Top of Page
   

- Advertisement -