You can't use the Column alias directly in a where cause, you need to put in a derived dataset (table)
i.e. SELECT * FROM ( SELECT substring(colname ,charindex('|',colname)+1, charindex('|',colname, charindex('|',colname)+1) - charindex('|',colname) -1) as "PID" FROM SomeTable ) as DerivedTable WHERE DerivedTable.PID = something Don Verhagen www.REMOVEemjackTHIS.com > -----Original Message----- > From: u2-users-boun...@listserver.u2ug.org [mailto:u2-users- > boun...@listserver.u2ug.org] On Behalf Of George Gallen > Sent: Wednesday, December 28, 2011 3:38 PM > To: U2 Users List > Subject: Re: [U2] MS-SQL Question > > It came back with unknown column error. I'll have to play with it > again, it's possible I typed something wrong, > But at least for now, it's working the other way I set it up. > > Thanks > George > > > -----Original Message----- > From: u2-users-boun...@listserver.u2ug.org [mailto:u2-users- > boun...@listserver.u2ug.org] On Behalf Of George Gallen > Sent: Thursday, 29 December 2011 2:51 AM > To: U2 Users > Subject: [U2] MS-SQL Question > > I'm querying a sequel server , I have a column in one table that the > data is in the form of "X|Y|Z". > > I have the following in my SELECT: > > substring(colname ,charindex('|',colname)+1, charindex('|',colname, > charindex('|',colname)+1) - charindex('|',colname) -1) as "PID" > > Is there anyway that I can then use the "PID" designation in a where > clause, without having to retype the string again? > > > I can't add a virtual column to the table , and I can't add a procedure > either. > > _______________________________________________ > U2-Users mailing list > U2-Users@listserver.u2ug.org > http://listserver.u2ug.org/mailman/listinfo/u2-users > _______________________________________________ > U2-Users mailing list > U2-Users@listserver.u2ug.org > http://listserver.u2ug.org/mailman/listinfo/u2-users > _______________________________________________ > U2-Users mailing list > U2-Users@listserver.u2ug.org > http://listserver.u2ug.org/mailman/listinfo/u2-users > _______________________________________________ > U2-Users mailing list > U2-Users@listserver.u2ug.org > http://listserver.u2ug.org/mailman/listinfo/u2-users > _______________________________________________ > U2-Users mailing list > U2-Users@listserver.u2ug.org > http://listserver.u2ug.org/mailman/listinfo/u2-users _______________________________________________ U2-Users mailing list U2-Users@listserver.u2ug.org http://listserver.u2ug.org/mailman/listinfo/u2-users