Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > Sybase

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 06:18 PM
Thakur
 
Posts: n/a
Default sybase sql help

HI

I hv a table that contains a column which contains unformated data .
Like
Col1 varchar(35) col1 varchar(35)
AS PD FT AS-PD-FT
AS-PD GH AS-PD-GH
R GT-TY R-GT-TY
S G- S-G

i hv 2 update d table. any idea??


Sameer

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 06:18 PM
jcolins
 
Posts: n/a
Default Re: sybase sql help

give some more detail on what u reqd.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 06:18 PM
Thakur
 
Posts: n/a
Default Re: sybase sql help

Before After
Col1 varchar(35) col1 varchar(35)
------------------------------------
-------------------------------
AS PD FT AS-PD-FT
AS-PD GH AS-PD-GH
R GT-TY R-GT-TY
S G- S-G

i want each word in this column should be separated with "-". This
table contains around 90,000 records and i hv to modify that column only

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 06:18 PM
Mark A. Parsons
 
Posts: n/a
Default Re: sybase sql help

Assuming you're running ASE 12.5.0.3+ you could use the str_replace()
function to replace blanks with '-':

update <table_name>
set Col1 = str_replace(Col1,' ','-')


This assumes that Col1 values do not start with blanks.

This update will not solve the problem with the last example where Col1
currently ends with a '-'. This could be fixed with some additional code
.... either an additional 'update' or a more complicated change to the above
'update'.

You really need to provide a complete set of specs for what the Col1 data
currently looks like ... leading/trailing spaces? need to remove
leading/trailing '-'s? need to remove any other leading/trailing
characters other than space or '-'?

Thakur wrote:

> Before After
> Col1 varchar(35) col1 varchar(35)
> ------------------------------------
> -------------------------------
> AS PD FT AS-PD-FT
> AS-PD GH AS-PD-GH
> R GT-TY R-GT-TY
> S G- S-G
>
> i want each word in this column should be separated with "-". This
> table contains around 90,000 records and i hv to modify that column only
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-08-2008, 06:18 PM
Mark A. Parsons
 
Posts: n/a
Default Re: sybase sql help

Also ...

- does this have to be done as 1 'update' or can multiple 'update's be used?

- is this a one time thing or do you have to constantly issue this update?
(it may be of benefit to add some code to the client and/or a trigger to
make sure the data is formatted 'properly' at the time it's entered into
the database)

Mark A. Parsons wrote:

> Assuming you're running ASE 12.5.0.3+ you could use the str_replace()
> function to replace blanks with '-':
>
> update <table_name>
> set Col1 = str_replace(Col1,' ','-')
>
>
> This assumes that Col1 values do not start with blanks.
>
> This update will not solve the problem with the last example where Col1
> currently ends with a '-'. This could be fixed with some additional
> code ... either an additional 'update' or a more complicated change to
> the above 'update'.
>
> You really need to provide a complete set of specs for what the Col1
> data currently looks like ... leading/trailing spaces? need to remove
> leading/trailing '-'s? need to remove any other leading/trailing
> characters other than space or '-'?
>
> Thakur wrote:
>
>> Before After
>> Col1 varchar(35) col1 varchar(35)
>> ------------------------------------
>> -------------------------------
>> AS PD FT AS-PD-FT
>> AS-PD GH AS-PD-GH
>> R GT-TY R-GT-TY
>> S G- S-G
>>
>> i want each word in this column should be separated with "-". This
>> table contains around 90,000 records and i hv to modify that column only
>>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:03 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145