| Author |
Topic |
|
hspatil31
Posting Yak Master
182 Posts |
Posted - 2010-07-14 : 05:39:21
|
| Dear All,I am having following queary and output this is coming from DB table.Queary: Select EmpName From EmployeeMaster;Output: Nilesh Sachin Harish Atul PriteshNow i want to add 'All Employee' in this output, that is not in table, that is a string like,Output: All Employee Nilesh Sachin Harish Atul PriteshSo can anybody tell me how to add this one in output.Thanks and Regard's Harish Patil |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2010-07-14 : 05:41:22
|
| select empname from (select 1 as id, 'All Employee' as EmpName union Select 2 as id,EmpName From EmployeeMaster)sorder by id |
 |
|
|
hspatil31
Posting Yak Master
182 Posts |
Posted - 2010-07-14 : 06:06:11
|
Dear bklr,And if i want to show multiple value suppose i have added one more column EmpID like,select empname,EmpID from (select 1 as id, 'All Employee' as EmpName union Select 2 as id,EmpName,EmpID From EmployeeMaster)sorder by idMeans suppose i want to show one more column EmpID also it giving error,'All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.'quote: Originally posted by bklr select empname from (select 1 as id, 'All Employee' as EmpName union Select 2 as id,EmpName From EmployeeMaster)sorder by id
|
 |
|
|
sql-programmers
Posting Yak Master
190 Posts |
Posted - 2010-07-14 : 06:13:46
|
| Try this,select 0 as EmpID,'All Employee' as EmpName unionSelect EmpID,EmpName From EmployeeMasterorder by 1SQL Server Programmers and Consultantshttp://www.sql-programmers.com/ |
 |
|
|
hspatil31
Posting Yak Master
182 Posts |
Posted - 2010-07-14 : 06:28:28
|
Dear Sir,Thanks for the reply. It's working.Now i want suppose in same queary department also want to show.LikeOutput: EmpName EmpID EmpDeptAll Employee 0 All DepartmentNilesh 1 BBSachin 2 CCHarish 3 DDAtul 4 EEPritesh 5 FFI tried but it is giving again error,Tried queary,select 0 as EmpID,'All Employee' as EmpName unionselect 0 as EmpID,'All Department' as EmpDeptunion Select EmpID,EmpName,EmpDept From EmployeeMasterorder by 1quote: Originally posted by sql-programmers Try this,select 0 as EmpID,'All Employee' as EmpName unionSelect EmpID,EmpName From EmployeeMasterorder by 1SQL Server Programmers and Consultantshttp://www.sql-programmers.com/
|
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2010-07-14 : 06:32:41
|
| select 0 as EmpID,'All Employee' as EmpName, 'All Department' as EmpDeptunionSelect EmpID,EmpName,EmpDept From EmployeeMasterorder by 1when u r using union the both select statements should have same number of the column with same datatypes....... |
 |
|
|
hspatil31
Posting Yak Master
182 Posts |
Posted - 2010-07-14 : 07:01:24
|
Dear bklr,Thanks very much for reply. I am trying same example in Oracle10g with sqldeveloper but this is not working.So can you plz tell me y it is not working ?quote: Originally posted by bklr select 0 as EmpID,'All Employee' as EmpName, 'All Department' as EmpDeptunionSelect EmpID,EmpName,EmpDept From EmployeeMasterorder by 1when u r using union the both select statements should have same number of the column with same datatypes.......
|
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2010-07-14 : 07:08:18
|
| try thisselect 0 as EmpID,'All Employee' as EmpName, 'All Department' as EmpDept from dualunionSelect EmpID,EmpName,EmpDept From EmployeeMasterorder by 1 |
 |
|
|
hspatil31
Posting Yak Master
182 Posts |
Posted - 2010-07-14 : 07:27:56
|
Dear bklr,Thanks very much. My problem is solved. Is there any method to give point or automaticaly u will get.quote: Originally posted by bklr try thisselect 0 as EmpID,'All Employee' as EmpName, 'All Department' as EmpDept from dualunionSelect EmpID,EmpName,EmpDept From EmployeeMasterorder by 1
|
 |
|
|
|