Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
String t=xyz;
SQL
select * from table1 where name = t;


why is this not responding ?
Posted
Comments
Richard C Bishop 20-Mar-14 16:30pm    
The context of your question is not clear. You cannot declare variables the same way in T-SQL as you do C#.

1 solution

If you want to create a variable and use it in a query, it would look something like this:
DECLARE @t varchar(15)

SET @t = 'xyz'

SELECT * FROM table1 WHERE name = @t
 
Share this answer
 
Comments
Bharat_Jain 20-Mar-14 16:38pm    
But I am using JDBC So how it is possible ?
Richard C Bishop 20-Mar-14 16:41pm    
Are you wanting to execute this query from code-behind?
Bharat_Jain 20-Mar-14 16:51pm    
Yes . Supposing that i have 2 JFrame and in first JFrame i have a textbox and a button. when i click that button the data of that text field is transferred to another Jframe and then stored in variable a on other JFrame. Now suppose that variable is a. and i am trying something like this on second jFrame to print data based on where condition

String a=xyz;
select * from table1 where name=a;

the problem is i am not able to fetch the value stored in a variable to execute query .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900