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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Complex Query...for me

Author  Topic 

jesus4u
Posting Yak Master

204 Posts

Posted - 2002-08-13 : 09:15:29
Can u help me?

How do I write this sql?

I need to delete any records where Column1 NOT = 'PK' and Column2 NOT = '0.00' and Column3's FIRST character is the string '6'?

Thanks

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-08-13 : 09:17:29

delete <table>
where
Column1 <> 'PK' and
Column2 <> '0.00' and
left(Column3,1) = '6'

 


Jay White
{0}
Go to Top of Page

dsdeming

479 Posts

Posted - 2002-08-13 : 09:18:30
Try this:

DELETE FROM tablename
WHERE Column1 <> 'PK'
AND Column2 <> '0.00'
AND LEFT( Column3, 1 ) = '6'



Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2002-08-13 : 10:21:46
quote:

LEFT( Column3, 1 ) = '6'



Column3 LIKE '6%'

LEFT doesn't produce sargable conditions (which is stupid, but there you go).


Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2002-08-13 : 11:32:19
assuming none of the fields are null.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

sql_learner
Starting Member

7 Posts

Posted - 2002-08-14 : 05:20:07
PATINDEX('%6%',Column3) > 0 runs faster than using LIKE

Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-08-14 : 08:01:06
quote:

PATINDEX('%6%',Column3) > 0 runs faster than using LIKE



And also doesn't meet the requirements...

maybe you mean
PATINDEX('6%',Column3) > 0

Jay White
{0}
Go to Top of Page
   

- Advertisement -