Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT statement

Status
Not open for further replies.

nerd19

Technical User
Joined
Jun 6, 2007
Messages
39
Location
US
I have a table with a bunch of districts where the fieldname is DistCode. I have a select statement as follows: SELECT distcode = 'sta' from tableDistCode
What i want to do is replace 'sta' in the results with 'state', how can i do this. Thanks

 
SELECT REPLACE(distcode, 'sta', 'state')
 
I have tried that but i recieve that 'no column was specified for column 1 of DistCode'
 
got it, had to do a distcode = replace....

Thanks tho
 
Code:
SELECT REPLACE(distcode, 'sta', 'state') 
FROM YourTable
But I'll do this:
Code:
SELECT CASE WHEN distcode = 'state'
            THEN distcode
       ELSE REPLACE(distcode, 'sta', 'state') END AS DistCode
FROM YourTable

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top