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
 General SQL Server Forums
 New to SQL Server Programming
 substring help

Author  Topic 

gavakie
Posting Yak Master

221 Posts

Posted - 2008-12-17 : 12:13:13
I have a column with picture links some have a /picture.jpg others just have picture.jpg I need all to have a slash in front of them how can I do that with a substring?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-17 : 12:17:19
[code]UPDATE table
SET column='/'+column
WHERE left(column,1) <> '/'[/code]
Go to Top of Page

gavakie
Posting Yak Master

221 Posts

Posted - 2008-12-17 : 12:31:13
I dont have permissions to do an update to the table so I need another way thanks though
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-17 : 12:33:08
then do it while retrieving data in select

SELECT CASE WHEN left(column,1) = '/' THEN column ELSE '/'+column END as Col FROM Table
Go to Top of Page

gavakie
Posting Yak Master

221 Posts

Posted - 2008-12-17 : 12:41:13
there isnt a way for a substring?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-17 : 12:45:37
no need whats the problem with case statement?
Go to Top of Page

gavakie
Posting Yak Master

221 Posts

Posted - 2008-12-17 : 12:49:53
I keep getting a bad charecter in format.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-17 : 12:55:04
bad character? can you post it? whats the character you're getting?
Go to Top of Page

gavakie
Posting Yak Master

221 Posts

Posted - 2008-12-17 : 12:55:54
I think its complaining about the data type and when I try to convert or cast I still get the error.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-17 : 12:57:57
post the error msg
Go to Top of Page
   

- Advertisement -