Geeks Talk

Prepare for your Next Interview




please, help me

This is a discussion on please, help me within the SQL forums, part of the Databases category; i have emp table it contains empno,ename,sal,sal level i need sal by thouthands = * SAL LEVEL if sal = 1000 than sal level =* if sal = 2000 than sal level =** ...


Go Back   Geeks Talk > Databases > SQL

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 02-09-2008
Junior Member
 
Join Date: Feb 2008
Location: Egypt
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Mazro is on a distinguished road
Question please, help me

i have emp table it contains

empno,ename,sal,sal level

i need

sal by thouthands = * SAL LEVEL

if sal = 1000 than sal level =*
if sal = 2000 than sal level =**
if sal = 3400 than sal level =***
if sal = 15000 than sal level =***************

i donot want it static

Thanks

Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-09-2008
Expert Member
 
Join Date: Apr 2007
Location: Bangalore
Posts: 447
Thanks: 20
Thanked 54 Times in 54 Posts
susarlasireesha is on a distinguished road
Re: please, help me

Try this
sql> set serveroutput on;

declare
cursor c1 is select empno,sal,trunc(sal/1000,0) lvl from emp;
c1r c1%rowtype;
x varchar2(255);
begin
open c1;
loop
fetch c1 into c1r ;
exit when c1%notfound;
x:=null;
if c1r.lvl >=1 then
for i in 1..c1r.lvl
loop
x:=x||'*';
end loop;
dbms_output.put_line(c1r.empno||' '||c1r.sal||' '||x);
else
dbms_output.put_line(c1r.empno||' '||c1r.sal||' '||'less than 1000');
end if;
end loop;
close c1;
end;
Reply With Quote
The Following User Says Thank You to susarlasireesha For This Useful Post:
  #3 (permalink)  
Old 02-09-2008
Junior Member
 
Join Date: Feb 2008
Location: Egypt
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Mazro is on a distinguished road
Re: please, help me

thank you very much

i am Beginner in sql

and i need a simpel answer
Reply With Quote
  #4 (permalink)  
Old 02-09-2008
Junior Member
 
Join Date: Nov 2007
Posts: 8
Thanks: 0
Thanked 1 Time in 1 Post
prashanth.n is on a distinguished road
Re: please, help me

Hi,

Try below query

select sal=
case
when sal> 1000 and sal <2000 then '*'
when sal> 2000 and sal <3000 then '**'
end from emp
Reply With Quote
  #5 (permalink)  
Old 02-11-2008
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,432
Thanks: 8
Thanked 125 Times in 112 Posts
debasisdas will become famous soon enoughdebasisdas will become famous soon enough
Re: please, help me

Try to use the following.

It is a simple answer for EMP table.

Code:
select decode(round(sal/1000),1,'*',2,'**',3,'***',4,'****',5,'*****',6,'******',7,'*******',8,'********',9,'*********',10,'**********') from emp
Reply With Quote
  #6 (permalink)  
Old 02-11-2008
Expert Member
 
Join Date: Apr 2007
Location: Bangalore
Posts: 447
Thanks: 20
Thanked 54 Times in 54 Posts
susarlasireesha is on a distinguished road
Re: please, help me

little change to above post
select decode(TRUNC(sal/1000),1,'*',2,'**',3,'***',4,'****',5,'*****',6,'******',7,'*******',8,'********',9,'*********',10,'**********') from SCOTT.emp
use trunc in place of round because 1600 is rounded to 2000
Reply With Quote
  #7 (permalink)  
Old 02-11-2008
Junior Member
 
Join Date: Jan 2008
Location: COIMBATORE,INDIA
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Prabhakaran_220162 is on a distinguished road
Re: please, help me

Hi you can try this select empno,ename,sal,replicate('*',round(sal,-3)/1000) ---this replicate command is for sal level
Reply With Quote
  #8 (permalink)  
Old 02-11-2008
Junior Member
 
Join Date: Jan 2008
Location: COIMBATORE,INDIA
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Prabhakaran_220162 is on a distinguished road
Re: please, help me

Quote:
Originally Posted by Prabhakaran_220162 View Post
Hi you can try this SIMPLE TRANSACT SQL COMMAND

Select empno,ename,sal,replicate('*',round(sal,-3)/1000)
---the above replicate command is for sal level
try the above Transact SQl command and let me know how it works
Reply With Quote
  #9 (permalink)  
Old 02-12-2008
Junior Member
 
Join Date: Feb 2008
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
expertsharingdotcom is on a distinguished road
Re: please, help me

My friend this works better for you in oracle

select lpad('*',trunc(sal/1000),'*') from emp
Reply With Quote
The Following User Says Thank You to expertsharingdotcom For This Useful Post:
  #10 (permalink)  
Old 02-18-2008
Junior Member
 
Join Date: Feb 2008
Location: Egypt
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Mazro is on a distinguished road
Re: please, help me

Quote:
Originally Posted by expertsharingdotcom View Post
My friend this works better for you in oracle

select lpad('*',trunc(sal/1000),'*') from emp
thank you for all

i try this answer and i found it is the best way i need

thanks expertsharingdotcom

Reply With Quote
Reply

  Geeks Talk > Databases > SQL


Thread Tools
Display Modes



All times are GMT -4. The time now is 08:41 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved