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 |
|
unicorn23
Starting Member
3 Posts |
Posted - 2008-04-01 : 18:54:52
|
| Hi all,I have the situation below. I can't use dual. Thank you for your time.Example Query:select namefrom employee where id=1;Result:0 rows selectedWanted Result:1 row selected |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-04-01 : 18:55:58
|
| IF NOT EXISTS (select * from employee where id=1) ..put something hereTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
unicorn23
Starting Member
3 Posts |
Posted - 2008-04-01 : 19:48:33
|
HiThanks for the reply. :)I can only use simple sql(result should be from one select query).I do not think I can use IF EXISTS. Sorry for not clarifying earlier.I can the idea of using count, so it count is 0, assign the value to null. However, the syntax is wrong as I cant put count in decode.SQL Error: ORA-00937: not a single-group group functionAny pointers are appreciatedselect decode(count(employee_id), 0, null, employee_id) from(select employee_idfrom employeeswhere employee_id=1); |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-04-01 : 20:02:26
|
| Looks like you are using Oracle, so you'd be better off posting your question in an Oracle forum such as the one over at dbforums.comThis site is for Microsoft SQL Server.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
unicorn23
Starting Member
3 Posts |
Posted - 2008-04-01 : 20:10:36
|
| Hi tkizer,Thanks for the fast replies! :) |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2008-04-01 : 22:38:56
|
| Think you want a single row with a null entry if nothing is foundselect coalesce(a.name, b.name)from(select name = convert(varchar(100),null)) as aleft join (select name from employee where id=1) as bon 1=1Will have to change that a bit for oracle but the concept should work.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|