SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with SQL query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dean_w
Starting Member

United Kingdom
2 Posts

Posted - 06/01/2012 :  13:41:45  Show Profile  Reply with Quote
Hi,
I need to remove live usernames from a couple of tables in a SQL database so that it can be sent to a 3rd party for analysis.

So for example I have 2 columns (UserKey and URI)

Row A: - UserKey = 1, URI = sip:userA@abc.com
Row B: - UserKey = 2, URI = sip:+4412345678@abc.com
Row C: - UserKey = 3. URI = sip:userC@abc.com
etc

Only the usernames need to be anonymised, not the telephone numbers.

So, I came up with:

UPDATE [qoemetrics].[dbo].[User]
SET URI=[UserKey] + 'abc.com'
WHERE URI LIKE '%sip:[a-z]%'

I wanted to remove the value for URI column, then take the numeric value for UserKey column (as this will always be unique) and append abc.com, but it fails because it won't join text to a numeric number.

I dont want it to change anything with a telephone number, hence the section to look for only [a-z]. So output I want is for example:

Row A: - UserKey = 1, URI = sip:1@abc.com
Row B: - UserKey = 2, URI = sip:+4412345678@abc.com (Unchanged)
Row C: - UserKey = 3, URI = sip:3@abc.com

Does anyone have a suggestion on how I can make this query work?

Thanks,
Dean

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 06/01/2012 :  23:40:14  Show Profile  Reply with Quote
UPDATE [qoemetrics].[dbo].[User]
SET URI=CAST([UserKey] AS varchar(5))+ 'abc.com'
WHERE URI LIKE '%sip:[a-z]%'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

vijays3
Constraint Violating Yak Guru

India
311 Posts

Posted - 06/02/2012 :  11:00:14  Show Profile  Reply with Quote
quote:
Originally posted by visakh16

UPDATE [qoemetrics].[dbo].[User]
SET URI=CAST([UserKey] AS varchar(5))+ 'abc.com'
WHERE URI LIKE '%sip:[a-z]%'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/








Hi visakh 

your query eliminate the sip string .






create table #temp(UserKey  int,URI varchar(30))

insert into #temp(UserKey,URI)
select 1,'sip:userA@abc.com'
union all
select 2,'sip:+4412345678@abc.com'
union all 
select 3,'sip:userC@abc.com'



update #temp set URI = 'sip:'+ cast(UserKey as varchar(20))+'@abc.com'

where URI like 'sip:[a-z][A-Z]%'


select * from #temp


Vijay is here to learn something from you guys.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 06/02/2012 :  13:45:40  Show Profile  Reply with Quote
quote:
Originally posted by vijays3

quote:
Originally posted by visakh16

UPDATE [qoemetrics].[dbo].[User]
SET URI=CAST([UserKey] AS varchar(5))+ 'abc.com'
WHERE URI LIKE '%sip:[a-z]%'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/








Hi visakh 

your query eliminate the sip string .






create table #temp(UserKey  int,URI varchar(30))

insert into #temp(UserKey,URI)
select 1,'sip:userA@abc.com'
union all
select 2,'sip:+4412345678@abc.com'
union all 
select 3,'sip:userC@abc.com'



update #temp set URI = 'sip:'+ cast(UserKey as varchar(20))+'@abc.com'

where URI like 'sip:[a-z][A-Z]%'


select * from #temp


Vijay is here to learn something from you guys.


i just reused OPs suggestion itself
i only modified the casting part


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dean_w
Starting Member

United Kingdom
2 Posts

Posted - 06/03/2012 :  05:42:46  Show Profile  Reply with Quote
Great thanks, will give this a try.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000