Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Replace


Replace

Author
Message
chandrasekaran.ganapathy
chandrasekaran.ganapathy
Valued Member
Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)

Group: General Forum Members
Points: 72 Visits: 92
Hi

Consider this table

Man_name Model

Motorola MotoQ
Motorola RAZR2
Nokia N73
Nokia 6100
Samsung C118


I have used Distinct Statement to retrieve the value.
Now I want to replace if the Man_Name comes 2nd time then I need to replace that value with "Blank".

Is it possible to do this?
Kingston Dhasian
Kingston Dhasian
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3001 Visits: 4995

; WITH cteTableName AS
(
SELECT ROW_NUMBER() OVER( PARTITION BY Man_name ORDER BY Model ) RowNum, *
FROM TableName
)

SELECT CASE WHEN RowNum > 1 THEN '' ELSE Man_name END Man_name, Model
FROM cteTableName



This should do it for you..


Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Adi Cohn-120898
Adi Cohn-120898
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2224 Visits: 6076
How do you define which record is the second record? When you have 2 values do you have a rule that according to it you know which one to update and which record to leave as it is? Assuming that you do it by a key, here is a small example of how to do it:

use tempdb
go

declare @tbl table (id int not null primary key, vc varchar(10))

insert into @tbl (id, vc)
select 1, 'aaa'
union
select 2, 'bbb'
union
select 3, 'aaa'
union
select 4, 'aaa'
union
select 5, 'ccc';


with NotToUpdate as(
select MIN(id) as id, vc
from @tbl
group by vc)
update t
set t.vc = ''
from @tbl t left join NotToUpdate NTU on t.id = NTU.id
where NTU.id is null

select * from @tbl



Adi

--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
chandrasekaran.ganapathy
chandrasekaran.ganapathy
Valued Member
Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)

Group: General Forum Members
Points: 72 Visits: 92
Hi Kingston,

It is working. Just give me small explanation how this code is working..... If you explain it would be great help.
chandrasekaran.ganapathy
chandrasekaran.ganapathy
Valued Member
Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)

Group: General Forum Members
Points: 72 Visits: 92
You are spliting the data by Partition and assigning row numbers.

After that for row_number> 1 you are assiging blank right.

Is my understanding is correct?
Kingston Dhasian
Kingston Dhasian
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3001 Visits: 4995
You are right:-)


Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
chandrasekaran.ganapathy
chandrasekaran.ganapathy
Valued Member
Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)Valued Member (72 reputation)

Group: General Forum Members
Points: 72 Visits: 92
Thanks Kingston..

Meet you with another problem.....

Bye!!!
shobanapraveen
shobanapraveen
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 Visits: 46
Hi Friends,

replace('$filter', 'itime', 'am.itime')

Can any one help with replace command?

This statement is not getting replaced.

Thanks
Shobana
mahmad_khoja
mahmad_khoja
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1193 Visits: 83
Hi,

Here '$filter' word does not contains 'itime' thats why it is not being replaced.

Check below statement for your reference.

select REPLACE('abcdef','ef','EF')
shobanapraveen
shobanapraveen
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 Visits: 46
Thanks for your immediate reply.................



in $filter they are using conditions like itime>= and itime<=......



select distinct split_part(split_part(cp.msg, 'src=',1),',',1),split_part(split_part(cp.msg, 'user=''',2),',',1) as user ,am.itime,am.dtime,am.url from "FGT60B3908669009-wlog-1380091698" am join "SYSLOG-C0A80A41-glog-1380347892" cp on cast(am.src as character varying)=cast((split_part(split_part(cp.msg, 'src=',2),',',1) ) as character varying) where am.src='192.168.10.23' and replace('$filter', 'itime', 'am.itime')


This is my query......

if the user what 1 day reports it takes long time for querying because of large data..... so i want to replace itime with my am.itime in $ filter............


for more details pls come online in gmail.(shobanapraveen80@gmail.com)


Thanks,
Shobana
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search