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 Statement From Variable Value

Author  Topic 

paramu
Posting Yak Master

151 Posts

Posted - 2009-03-16 : 10:40:55
I want to repair the following, I can't identify what's wrong with this.

pp1="17"

select * from emp_master where substr(emp_id,1,2)=pp1

How to use by this type of select from variable values?

Thanks & helps are highly appreciated

Paramu @ PARANTHAMAN

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-16 : 10:43:38
[code]
DECLARE @pp1 varchar(2)
SET @pp1='17'
select * from emp_master where cast(emp_id as varchar(20)) like @pp1 + '%'
[/code]
Go to Top of Page

paramu
Posting Yak Master

151 Posts

Posted - 2009-03-16 : 11:06:31
Try to give me in single line , will be usefull to call up from vb.net

Thanks

Paramu @ PARANTHAMAN
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-16 : 11:12:40
its single line. i just declared the variable thats all. the query to use is

"select * from emp_master where cast(emp_id as varchar(20)) like " & your pp1 variable in vb.net & "'%'"
Go to Top of Page

paramu
Posting Yak Master

151 Posts

Posted - 2009-03-16 : 11:54:00
Both are giving problem

select * from emp_master where cast(emp_id as varchar(10)) like " & kyprs & "'%'"

and

DECLARE @pp1 varchar(10) SET @pp1='&kyprs' select * from emp_master where cast(emp_id as varchar(10)) like @pp1 + '%'", con)
-----------------------------------
but if the above,
DECLARE @pp1 varchar(10) SET @pp1='17' select * from emp_master where cast(emp_id as varchar(10)) like @pp1 + '%'", con)

is working fine.

So any better idea.......

Thanks Again


Paramu @ PARANTHAMAN
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-16 : 12:37:50
where's kyprs declared?
Go to Top of Page

paramu
Posting Yak Master

151 Posts

Posted - 2009-03-17 : 03:02:01
Variable kyprs is from Frontend

Paramu @ PARANTHAMAN
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-17 : 10:37:26
what happened when you used first query?

"select * from emp_master where cast(emp_id as varchar(10)) like " & kyprs & "'%'"


Go to Top of Page
   

- Advertisement -