| Author |
Topic |
|
massspectrometry
Yak Posting Veteran
50 Posts |
Posted - 2007-07-11 : 00:05:06
|
| I'm using SQL Server 2000. I had data that looks like this1234, successful1234, invalid message4444, winner of prize4444, successful4444, invalid format6666, hello6666, bulk sms1111, invalid msg1111, invalid formati need to display only the data with 'successful'. And the data that don't have 'successful', can choose either one of it.. So the output will look like this. 1234, successful4444, successful6666, hello <--- can choose either one (hello or bulk sms)1111, invalid format <--- can choose either oneCan someone please help me :( |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-11 : 00:21:58
|
[code]DECLARE @TABLE TABLE( code int, data varchar(30))INSERT INTO @TABLESELECT 1234, 'successful' UNION ALLSELECT 1234, 'invalid message' UNION ALLSELECT 4444, 'winner of prize' UNION ALLSELECT 4444, 'successful' UNION ALLSELECT 4444, 'invalid format' UNION ALLSELECT 6666, 'hello' UNION ALLSELECT 6666, 'bulk sms' UNION ALLSELECT 1111, 'invalid msg' UNION ALLSELECT 1111, 'invalid format'SELECT code, data = CASE WHEN SUM(CASE WHEN data = 'successful' THEN 1 ELSE 0 END) > 0 THEN 'successful' ELSE MAX(data) ENDFROM @TABLEGROUP BY code/*code data ----------- ------------------------------ 1111 invalid msg 1234 successful 4444 successful 6666 hello*/[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
massspectrometry
Yak Posting Veteran
50 Posts |
Posted - 2007-07-11 : 02:27:01
|
| Wow..thank you.. it works perfectly.. Thanks khtan! |
 |
|
|
massspectrometry
Yak Posting Veteran
50 Posts |
Posted - 2007-07-11 : 03:23:02
|
| erm..i need another help...my current data looks like this.601930609571460246320169272494601236253346012286988960124701486168232465i want to insert 60 in the front of each data.. How am i to do that? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-11 : 03:25:25
|
[code]update tset col = '60' + colfrom yourtable t[/code]Why don't you store the country code in separate column ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
massspectrometry
Yak Posting Veteran
50 Posts |
Posted - 2007-07-11 : 03:36:15
|
| Opsss.. when i tried update telephoneset phoneno = '60' + phonenofrom telephonethe output looks like this60601234567896060123456789601234567896012345678960123456789i dont want to modify all the data..just the data that dont have 60 in front of them.. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-11 : 03:45:19
|
[code]UPDATE tSET phoneno = '60' + phonenoFROM telephone tWHERE phoneno NOT LIKE '60%'[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
massspectrometry
Yak Posting Veteran
50 Posts |
Posted - 2007-07-11 : 04:04:35
|
| thanks..it works... but one problem thoughi have data that looks like this0123456789when i execute the above queryit becomes600123456789how to elimate the second or third zero (0)? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-11 : 04:07:17
|
[code]UPDATE tSET phoneno = CASE WHEN left(phoneno, 1) = '0' THEN '6' ELSE '60' END + phonenoFROM telephone tWHERE phoneno NOT LIKE '60%'[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
massspectrometry
Yak Posting Veteran
50 Posts |
Posted - 2007-07-11 : 04:10:14
|
| erm..rite now i already execute it..so i had thousands of data that have double zero in it600123456789600987654321if i use the above query, will it eliminate the zero? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-11 : 04:13:42
|
quote: Originally posted by massspectrometry erm..rite now i already execute it..so i had thousands of data that have double zero in it600123456789600987654321if i use the above query, will it eliminate the zero?
Nope.use thisUPDATE tSET phoneno = REPLACE(phoneno, '600', '60')FROM telephone tWHERE phoneno LIKE '600%' KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
massspectrometry
Yak Posting Veteran
50 Posts |
Posted - 2007-07-11 : 04:19:07
|
| Wow..u really amazing in sql... If i know you personally, i would buy u a lunch.. Hehe.. Thanks! |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-11 : 04:33:04
|
 KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
massspectrometry
Yak Posting Veteran
50 Posts |
Posted - 2007-07-11 : 22:05:01
|
| hi.. i have some query that i want to solve. i had a data that looks like this. (it's actually a text messages where people sms in to win prizes) and it have to start with 'PRM'SMSReceived <-- column namePrm 65719471Prm 68516237PRM 72847410Prm 75031193PRM (SPACE) PINSEND TO32080 prm (space)36398226PRM < > 22733564Prm < 82848916 > pinPRM <36943554>how can i choose only the number? so the desired output will look like this..6571947168516237728474107503119332080 36398226227335648284891636943554please help.. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-11 : 23:01:39
|
search the script library in this forum. There is a script that does this. KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
massspectrometry
Yak Posting Veteran
50 Posts |
Posted - 2007-07-11 : 23:12:23
|
| i find two in the script library which is topic 'number pattern' and sum the cubes of numeric... can u give me a lead pls :( |
 |
|
|
massspectrometry
Yak Posting Veteran
50 Posts |
Posted - 2007-07-11 : 23:28:32
|
| i can't find it... please help :(( |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
massspectrometry
Yak Posting Veteran
50 Posts |
Posted - 2007-07-12 : 00:12:50
|
| (feel really stupid) how to use it? i run that script in my query analyzer and it said success.. then ? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-12 : 00:16:19
|
That is a user defined function. What you did is to create the function.See this line ?quote: -- USAGE: fn_extract_chars(string_to_search, 'letters' -or- 'numbers')
Use it as followsselect dbo.fn_extract_chars(SMSReceived, 'numbers')from yourtable KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
massspectrometry
Yak Posting Veteran
50 Posts |
Posted - 2007-07-12 : 00:25:10
|
| can we choose multiple column using that above query? lets say i have this query..SELECT dnyFrom as 'SMS From',max(dnySMSText) as 'SMS Received',max(dnyCustomerId) as 'Customer ID', dnyReason = CASE WHEN SUM(CASE WHEN dnyReason = 'Successful' THEN 1 ELSE 0 END) > 0 THEN 'successful' ELSE MAX(dnyReason) END FROM shldnysmsreceivedwhere dnycustomerid='PRM' anddnyDateReceived between '2006-12-01 00:00:00.000' and '2007-07-01 00:00:00.000' GROUP BY dnyFromorder by max(dnySmsText) ascand i want also to display another column with only numbers (like above) query.. can it be done? |
 |
|
|
Next Page
|