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 2005 Forums
 Transact-SQL (2005)
 re: insert query - column value manipulation!!

Author  Topic 

agarwasa2008
Posting Yak Master

109 Posts

Posted - 2009-10-07 : 18:23:53
I have the following query:

insert table1
(field1, sys_user)
select field1, system_user)
from .....

The issue is that the system_user has values as XYZ\abcdefg. So I want the column name to get the following value:

sys_user = abcdefg .

Please advice.

SA

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-10-07 : 18:53:20
DECLARE @s varchar(20)

SET @s = 'XYZ\abcdefg'

SELECT SUBSTRING(@s, CHARINDEX('\', @s) + 1, DATALENGTH(@s))

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -