November 19, 2015 at 9:56 am
I have a table: Table_1 as below:
IDDescription
1College 1 kaká
2University 1
3College 2
4University 2
I use sql select: Select * from Table_1 where Description like N'%College%'
=> Result:
IDDescription
1College 1 kaká
3College 2
But 'College' always change, so I want use a variable on it, sample:
Select * from Table_1 where Description like N'%' + @test-2 + '%'
but It work wrong
Please help to resolve them,
Thank you very much
November 19, 2015 at 10:21 am
November 19, 2015 at 10:29 am
November 19, 2015 at 10:31 am
vantuan02t1 (11/19/2015)
I have a table: Table_1 as below:IDDescription
1College 1 kaká
2University 1
3College 2
4University 2
I use sql select: Select * from Table_1 where Description like N'%College%'
=> Result:
IDDescription
1College 1 kaká
3College 2
But 'College' always change, so I want use a variable on it, sample:
Select * from Table_1 where Description like N'%' + @test-2 + '%'
but It work wrong
Please help to resolve them,
Thank you very much
Would this work?
Select * from Table_1 where CHARINDEX(@test, Description) > 0
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
November 19, 2015 at 10:46 am
vantuan02t1 (11/19/2015)
Naturally I will declare a variable, sample:Declare @test-2 varchar(50)
select @test-2 = 'College'
(1) Select * from Table_1 where Description like N'%' + @test-2 + '%'
But test result is different with
(2) Select * from Table_1 where Description like N'%College%'
I want result of (1) is the same (2)
You're certainly doing something different as both queries return the same result.
CREATE TABLE Table_1(
ID int,
Description nvarchar(50)
);
INSERT INTO Table_1
VALUES(1,'College 1 kaká')
,(2,'University 1')
,(3,'College 2')
,(4,'University 2')
Declare @test-2 varchar(50)
select @test-2 = 'College'
--(1)
Select * from Table_1 where Description like N'%' + @test-2 + '%'
--But test result is different with
--(2)
Select * from Table_1 where Description like N'%College%'
GO
DROP TABLE Table_1;
What are you actually doing?
November 19, 2015 at 10:47 am
Cotto vs Canelo Live Stream Tv Telecast
https://www.facebook.com/Miguel-Cotto-vs-Canelo-Alvarez-Live-Stream-PPV-Boxing-1503111929983691/
http://indy500live.us/Cotto vs Canelo Live Stream
November 19, 2015 at 11:05 am
vantuan02t1 (11/19/2015)
I want to use a variable (ex: @test-2) to replace value 'College' in LIKESample:
Select * from Table_1 where Description like N'%@test%'
We already know this. I already post a test which shows that the code is not a problem for that sample data. We need to have more accurate details on what's happening.
December 14, 2015 at 8:27 am
Thank you all, I think I had resolved it
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply