Solved

Replace placeholders in Recordset and then Sort

Posted on 2003-12-01
4
230 Views
Last Modified: 2012-06-27
Hi, I'm using ASP with MS SQL 2000.

I have a recordset that looks something like this. It has only one column, called Identity_Name:
  BCDE0001
  BCDE0002
  XXXX0001
  XXXX0002

For comparison purposes, I need to alter this recordset so that all the occurances of "XXXX" are replaced with another 4 character string. Then, the recordset needs to be re-sorted. Let's say that we change "XXXX" to "ABCD." The resulting recordset should look like this:
  ABCD0001
  ABCD0002
  BCDE0001
  BCDE0002

Does anyone know of a clever way to do this using SQL only? I'd rather not dump the recordset into an ASP array and then sort it.
0
Comment
Question by:tevelision
  • 3
4 Comments
 
LVL 30

Accepted Solution

by:
nmcdermaid earned 200 total points
ID: 9851514
UPDATE Table
SET Field = 'ABCD' + Right(Field,4)
WHERE LEN(Field) > 3
AND <You need a criteria to limit the fields that are updated>

Without a criteria it will update the whole lot. Do you have a criteria for the records that you want to update?



You can also sort on the fly, like so:


SELECT * FROM Table
ORDER BY 'ABCD' + Right(Field,4)
0
 

Author Comment

by:tevelision
ID: 9851550
Thanks for the response, nmcdermaid.

I want to avoid using the UPDATE statement since I don't want to change what's in the database. So the "XXXX" have to stay in the database table. Sorry, I should have said this in the first message.

I think you're on to something with that sort on-the-fly statement. Let me give that whirl.
0
 

Author Comment

by:tevelision
ID: 9851852
I found my answer:

SELECT     REPLACE(Identity_Name, 'XXXX', 'ABCD') AS Expr1
FROM        IdentityTable
ORDER BY Identity_Name

I'm still giving points to nmcdermaid for helping me realize that I can actually grab certain parts of a field. Thanks, man.
0
 

Author Comment

by:tevelision
ID: 9851868
Sorrly, there's an error in the last line.

SELECT     REPLACE(Identity_Name, 'XXXX', 'ABCD') AS Expr1
FROM        IdentityTable
ORDER BY Expr1
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to set UNMASK permission only to only one table in SQL Server 2016 ? 11 75
script to send html report 3 31
Oracle DB monitor SW 21 47
SqlServer no dupes 25 34
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now