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.
| Author |
Topic |
|
amirs
Constraint Violating Yak Guru
260 Posts |
Posted - 2010-01-12 : 22:37:16
|
| hii have following tabletb1col1 col2 col3 col4dia pw rdia pw r r0dia rw b p0dia 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, Col4FROM tb1WHERE 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 Sindolhttp://mytechnobook.blogspot.com/This information is provided "AS IS" with no warranties, and confers no rights. |
 |
|
|
amirs
Constraint Violating Yak Guru
260 Posts |
Posted - 2010-01-12 : 23:37:43
|
| thanks to replayit 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 querycol1 col2 col3 col4dia pw rdia pw r r0dia rw b p0dia rw b select col1,col2,col3,col4 from tblwhile 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. |
 |
|
|
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='') |
 |
|
|
|
|
|
|
|