Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
DLTaylor
Posting Yak Master
136 Posts |
Posted - 2007-09-11 : 09:40:45
|
I am very new to SQL programming and have a query i hope you can advise on.I used this site for help with replacing asci and character values in a string of text and came up with the following;-----------------------while @@rowcount > 0update xTxt_MriDrcPatient_Numbersset Telephone = replace(Telephone, substring(Telephone, patindex('%[^a-zA-Z0-9 ]%', Telephone), 1), '')where patindex('%[^a-zA-Z0-9 ]%', Telephone) <> 0while @@rowcount > 0update xTxt_MriDrcPatient_Numbersset Telephone = replace(Telephone, substring(Telephone, patindex('%[A-X]%', Telephone), 1), '')where patindex('%[A-Z]%', Telephone) <> 0-----------------------My question is; each statement works on its own but why when i try to run one after another the 2nd will not complete why?- is it down to @@rowcount?ThanksDan |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-09-11 : 09:51:10
|
When quitting the first update, the @@rowcount is zero. And thus never enters second update... E 12°55'05.25"N 56°04'39.16" |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-09-11 : 09:51:52
|
Add a dummy select between them.while @@rowcount > 0update xTxt_MriDrcPatient_Numbersset Telephone = replace(Telephone, substring(Telephone, patindex('%[^a-zA-Z0-9 ]%', Telephone), 1), '')where patindex('%[^a-zA-Z0-9 ]%', Telephone) <> 0declare @dummy intselect @dummy = 1while @@rowcount > 0update xTxt_MriDrcPatient_Numbersset Telephone = replace(Telephone, substring(Telephone, patindex('%[A-X]%', Telephone), 1), '')where patindex('%[A-Z]%', Telephone) <> 0 E 12°55'05.25"N 56°04'39.16" |
 |
|
Kristen
Test
22859 Posts |
Posted - 2007-09-11 : 10:33:11
|
I think I would prefer:DECLARE @intRowCount intSELECT @intRowCount = 1 -- Force first iterationwhile @intRowCount > 0BEGINupdate xTxt_MriDrcPatient_Numbersset Telephone = replace(Telephone, substring(Telephone, patindex('%[^a-zA-Z0-9 ]%', Telephone), 1), '')where patindex('%[^a-zA-Z0-9 ]%', Telephone) <> 0SELECT @intRowCount = @@rowcountENDSELECT @intRowCount = 1 -- Force first iterationwhile @intRowCount > 0BEGINupdate xTxt_MriDrcPatient_Numbersset Telephone = replace(Telephone, substring(Telephone, patindex('%[A-X]%', Telephone), 1), '')where patindex('%[A-Z]%', Telephone) <> 0SELECT @intRowCount = @@rowcountEND Kristen |
 |
|
DLTaylor
Posting Yak Master
136 Posts |
Posted - 2007-09-11 : 11:51:58
|
Thanks for your help.It now works perfectly. |
 |
|
|
|
|
|
|