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
 Transact-SQL (2000)
 Access to SQL

Author  Topic 

Pace
Constraint Violating Yak Guru

264 Posts

Posted - 2007-12-27 : 11:30:30
Hi,

I am struggling in converting this line from Access sql into sql server sql(?) Now in the past I have used the case statement but I am having difficulty with this one. The mid bit is throwing me so as I dont understand what its doing, I cant work out a way to convert it. Any help appreciated.

Here is the line (which is part of a select statement);
IIf(Left(Quotes.[Quote No],1)="Q","QT" & Mid(Quotes.[Quote No],3),Quotes.[Quote No]) AS PrintNo

"Impossible is Nothing"

nr
SQLTeam MVY

12543 Posts

Posted - 2007-12-27 : 12:08:28
case when Left(Quotes.[Quote No],1)="Q" then 'QT' + substring(Quotes.[Quote No],3,len(Quotes.[Quote No])) else Quotes.[Quote No] end as PrintNo



==========================================
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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-28 : 01:23:07
or

case when Quotes.[Quote No] like 'Q%' then 'QT' + substring(Quotes.[Quote No],3,len(Quotes.[Quote No])) else Quotes.[Quote No] end as PrintNo

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Pace
Constraint Violating Yak Guru

264 Posts

Posted - 2007-12-28 : 06:54:57
Thanks!

Both work exactly how I wanted them to. I now have a clearer understanding!

Arguably the first is a little neater no? However, the style of madhivanan's script is more to that of how I use it as stated in the question.

Thanks! not keen on this holiday programming

"Impossible is Nothing"
Go to Top of Page
   

- Advertisement -