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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 select querry

Author  Topic 

samitkumbhani
Starting Member

15 Posts

Posted - 2004-10-25 : 14:00:37
Hi,

I wanted to write a querry to retreive values which start with 'a'

select * from table_name where first_name like 'a%'

This is working fine but what i want to do is that the value 'a' is stored in a variable say temp. it changes all the time and based on its value i want to retieve the values from database.

Can someone please suggest me a solution.

Thanks in advance.

samit

X002548
Not Just a Number

15586 Posts

Posted - 2004-10-25 : 14:23:36
select * from myTabl99 where first_name like @temp + '%'

Like that?



Brett

8-)
Go to Top of Page

samitkumbhani
Starting Member

15 Posts

Posted - 2004-10-25 : 14:41:49
hi,

yes i wanted something like this
if temp is a variable and

temp = 'a'

then what should i do to write something like this including the variable temp in the querry.

select * from table_name where first_name like 'a%'

this is because i want to display the list aplhabetically and temp will change for each iteration varying from a - z

thanks

samit
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-10-25 : 15:30:40
I think Brett just gave you the answer .. did you try/understand it?

- Jeff
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2004-10-25 : 15:32:51
declare @temp varchar(1)
set @temp = 'a'
select * /*ouch...*/ from table_name where left(first_name,1) = @temp

rockmoose
/* Chaos is the nature of things...Order is a lesser state of chaos */
Go to Top of Page
   

- Advertisement -