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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select Query - From String Values...?

Author  Topic 

paramu
Posting Yak Master

151 Posts

Posted - 2012-01-05 : 04:12:55
Iam using sql server 2008.

Employee Table
==============

employee_no, employee Name
1001 SQL Team
1022 KRISTEN
1033 VISAKH
1044 PARAMU
SHP23 SOME NAME
35MECH ANOTHER
1021 SOME X
SHP15 SOME Y
25MECH SOME Z

TIMESHEET TABLE:
================
select * from timesheet_tbl tm where tm.employee_no in(select e1.employee_no from employee-tbl e1 where e1.emplyee_no>='1033' and e1.employee_no<='1021');

The above query gives only for employee_no 1033 and 1021

But I need
1033,1044,SHP23,35MECH,1021

So how to achieve like this ?

Thanks







Paramu @ PARANTHAMAN

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-01-05 : 04:17:51
but these emplyee_no "1044,SHP23,35MECH" does not falls between '1033' and '1021' !

run this and see how the employee_no is ordered

select * from [employee-tbl] order by employee_no



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

paramu
Posting Yak Master

151 Posts

Posted - 2012-01-05 : 04:33:54
Hi,Khtan thanks..when I check with order by it's missed some nos.
But my requirement is like the above I mentioned..Is it possible?

Thanks

Paramu @ PARANTHAMAN
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-01-05 : 04:38:56
when you use >= or <= it is considering the alphabetical order of the value in emplyee_no column.

quote:
But I need
1033,1044,SHP23,35MECH,1021



WHERE emplyee_no IN ('1033', '1044', 'SHP23', '35MECH', '1021')



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

paramu
Posting Yak Master

151 Posts

Posted - 2012-01-05 : 04:46:04
Hi Khtan...Thanks for the reply. Actually I don't the values, It has to be select from the Query.

Thanks Again...

Paramu @ PARANTHAMAN
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-01-05 : 04:54:10
so how do you decide what are the records you need ?

is there any other column in the table that you can based the criteria on ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

paramu
Posting Yak Master

151 Posts

Posted - 2012-01-05 : 05:19:25
As per the requirement no other column, I have to select from employee_no only.

Thank You Khtan.

Paramu @ PARANTHAMAN
Go to Top of Page
   

- Advertisement -