Solution for Query in Sql Server

Posted by Ajay.Kalol under Sql Server on 5/16/2012 | Points: 10 | Views : 970 | Status : [Member] | Replies : 5
SELECT 1 WHERE '00000SY' Like '00000S_'


Why this return 1 ???

I am Confused. Explain me.

Thanks..

Ajay
ajaypatelfromsanthal.blogspot.in



Responses

Posted by: Ravianand on: 5/16/2012 [Member] Starter | Points: 25

Up
0
Down
Because u not mention table Before Where Condition.

Regards,
Ravi

Ajay.Kalol, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pandians on: 5/16/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
Yeah. The script is Correct. It also working Correct!

"SELECT" not always expects "TABLE", It can be an expression instead!

1. '00000SY' is considering as Column/Column Value
2. '00000S_' is considering as an expression(Whild card character, "%" --> Multiple and "_" --> Single character)

So, The value '00000SY' Like '00000S_' is TRUE, so Its returning the Select expression "1"

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Ajay.Kalol, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 5/16/2012 [Member] Starter | Points: 25

Up
0
Down
I have changed query by wildcard to

SELECT 1 WHERE '00000SY' Like ' 00000S* '

SELECT 1 WHERE '00000SY' Like ' 00000S& '

But it's not return 1

Ajay
ajaypatelfromsanthal.blogspot.in

Ajay.Kalol, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pandians on: 5/16/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
Sorry, Multiple character is "%". Not "*"

Sorry for the Typo Err!

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Ajay.Kalol, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnetrajanikanth on: 5/17/2012 [Member] Starter | Points: 25

Up
0
Down
Actually this will just check whether the row exist or not. and returns the number of rows. this can be considered as an alternative for count(*). But this will improve the performance/response time(What ever it is)...

____________
www.flickr.com/photos/psdesigner/

Ajay.Kalol, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response