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 |
motoflyboy
Starting Member
2 Posts |
Posted - 2007-05-14 : 21:07:11
|
Hi,I have two questions, firstly..I am hoping there is a way to GROUP BY on a concatenated output like the following decode etc.. SELECTDECODE(PRIM_REASN,'','Reasons not entered',PRIM_REASN) || ' ' ||SECDY_REASN || ' ' || TERT_REASN) Downtime_Reasons,EVENT_DUR/60 MinutesFROM DOWNTIME_WEBWHEREDOWNTIME_WEB.TIMESTAMP>= (SELECT PRODN_SHIFT.START_DATIMEFROM PRODN_SHIFTWHEREPRODN_SHIFT.START_DATIME <=sysdate AND PRODN_SHIFT.END_DATIME > sysdate)ANDTRIM(DOWNTIME_WEB.STATUS_TEXT) = 'STOPPED'ANDTRIM(DOWNTIME_WEB.WORK_CTR_NAME) = 'PACK2'ORDER BY DOWNTIME_WEB.EVENT_DUR I have tried to put the DECODE etc into the GROUP BY statement but I get an error - " not a valid GROUP BY clause"Secondly, is there a way of modifying value in field A based on the value in field BErroneous example follows - in an effort to explain what I want to do (from above):DECODE(PRIM_REASN,'',(DECODE(EVENT_DUR,<200,"Low",>200,"High"),PRIM_REASN)ie:If PRIM_REASN is null I want EVENT_DUR to be tested to determine the new value for PRIM_REASN.Except that tthe above won't work and I don't know what the right function/argument should be..This is my first foray into SQL server, I am trying to migrate some access queries to work with web services and hence Xcelsius.Cheers. |
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-05-14 : 23:32:03
|
there is no DECODE() in sql server. also the string concat operator is + in t-sql, not ||. are you sure you aren't working in oracle? you might do better on an oracle forum. this forum is for sql server only. www.elsasoft.org |
|
|
motoflyboy
Starting Member
2 Posts |
Posted - 2007-05-14 : 23:56:40
|
Pardon me, please pretend I never darkened your door..... |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-05-15 : 06:17:13
|
Make use of a derived table.Peter LarssonHelsingborg, Sweden |
|
|
|
|
|
|
|