473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

replacing string problem, please help

Hello all,

I have a products table (see below)
Product State
Apple |1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|2 0|21|22|23|24|25|26|27|

I have to display the state data on a webform replacing the numbers with actual state names for example replace 1 with auckland, 2 with northland and so on. How to do this in SQL. Please help.

Cheers, Shilpa.
Aug 23 '07 #1
3 1236
debasisdas
8,127 Expert 4TB
As you have posted a question in the articles section it is being moved to SQL
Server Forum.

MODERATOR.
Aug 23 '07 #2
azimmer
200 Expert 100+
Hello all,

I have a products table (see below)
Product State
Apple |1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|2 0|21|22|23|24|25|26|27|

I have to display the state data on a webform replacing the numbers with actual state names for example replace 1 with auckland, 2 with northland and so on. How to do this in SQL. Please help.

Cheers, Shilpa.
Normally you have it as rows in a column rather than a string in a column but if that's how you have it:
Expand|Select|Wrap|Line Numbers
  1. declare @tmpstr as varchar(1024)
  2. select @tmpstr = State from Products where Product = 'Apple'
  3. @tmpstr=replace (@tmpstr,'|1|','auckland')
  4. @tmpstr=replace (@tmpstr,'|2|','northland')
  5. ...
  6.  
  7. select @tmpstr
  8.  
Aug 23 '07 #3
Normally you have it as rows in a column rather than a string in a column but if that's how you have it:
Expand|Select|Wrap|Line Numbers
  1. declare @tmpstr as varchar(1024)
  2. select @tmpstr = State from Products where Product = 'Apple'
  3. @tmpstr=replace (@tmpstr,'|1|','auckland')
  4. @tmpstr=replace (@tmpstr,'|2|','northland')
  5. ...
  6.  
  7. select @tmpstr
  8.  

Thanks for the reply there are two columns one is product, the other is state
product data is - Apple
State data is -|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|2 0|21|22|23|24|25|26|27|

As mentioned the state ids need to be replaced by state names and this is the resulting string which i need to get and display on the webform.

|Nor|Auc|Cor|Bay|Wai|Rot|Eas|Tau|Rua|Haw|Tar|Wan|M an|Wai|Wel|Nel|Mar|Wes|Chr|Can|Mtc|Wan|Que|Ota|Dun |Fio|Sou|

Your suggestions are much appreciated, Cheers, Shilpa.
Aug 28 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Tung Chau | last post by:
Hi, I need help with an efficient implementation of the above problem in C. Suffix tree does not seem to help much in this case. Any idea? Please help. Thanks. Tung Chau
11
by: lucky | last post by:
hi, i got file which contains "----------------" in a line. the line only contains this data as a saperation. using regular expression i want to i detify the line contains that data and replace...
12
by: anonymous | last post by:
Hello, I need to replace this char  with another char. However I am not able to acieve this. I tried this but it doesnt work: str = str.Replace(chr(asc(194)), "") Can somebody help ?
1
by: WT | last post by:
Hello, I was using hastable to store collection of objects of the same class MyClass. I start replacing this hastable by a Dictionary<string,MyClass>....but I was storing this hastable in cache...
14
by: Josh Baltzell | last post by:
I am having a lot more trouble with this than I thought I would. Here is what I want to do in pseudocode. Open c:\some.pdf Replace "Replace this" with "Replaced!" Save c:\some_edited.pdf I...
1
by: amraam35 | last post by:
Here is the problem. I have made a log in script that prompts you to log in with a username and password as the "splash screen" It is an unbounded forum that checks that the username and password...
32
by: FireHead | last post by:
Hello C World & Fanatics I am trying replace fgets and provide a equavivalant function of BufferedInputReader::readLine. I am calling this readLine function as get_Stream. In the line 4 where...
0
by: Lakhi | last post by:
hi frnds, I need small help in String replacement I need to replace the text using replceAll() with Case-Insensitve . Is there any regular expression for this? i have this expression ...
6
by: saif.shakeel | last post by:
Hi, I need to replace a string in xml file with something else.Ex - <SERVICEPARAMETER id="_775" Semantics="subfunction" DDORef="_54"> <SHORTNAME>rate</SHORTNAME> <LONGNAME>rate</LONGNAME>...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.