Urgent Help Required! [Resolved]

Posted by Sf_Hussain786 under Sql Server on 7/31/2012 | Points: 10 | Views : 1038 | Status : [Member] | Replies : 11
select ProductID,BrandID from Catalog.Product
where BrandID='-'

i use this query but i have a problm this query return those records whose BrandID
is "0" but in this case i think this query return 0 records.

Please Help me what i mistake in this query

sf_hussain786


Responses

Posted by: Sf_Hussain786 on: 7/31/2012 [Member] Starter | Points: 25

Up
0
Down

Resolved
what i share you its a database and i`m really sorry i can`t share database..

My Database like this

ProducttID | ProductName | BrandID
001 | abc | 0
002 | wbc | 0
003 | dbc | 1
004 | fbc | 1
005 | fDc | 0
006 | aDc | 2
007 | aec | 2
008 | acc | 0

when i write this query
select ProductID,BrandID from Catalog.Product
where BrandID='-'

its return 0(zero) records, but its return all those records whose id is 0

Like This

ProducttID | ProductName | BrandID
001 | abc | 0
002 | wbc | 0
005 | fDc | 0
008 | acc | 0

sf_hussain786

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

Posted by: Pandians on: 7/31/2012 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Normally, Non-Numeric some special characters being converted into 0(ZERO)

See the scenario...
Select CAST('-' as Int), CAST('' as Int), CAST(' ' as Int)

Go
All the column will be return as 0 (ZERO)

I hope "BrandID" column is INT, So when you try to compare the special character '-' (Its converted into 0(ZERO)).

But the following script will work as you expected...
select ProductID,BrandID from Catalog.Product where Cast(BrandID as varchar) = '-'


Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

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

Posted by: Vijayakumarp on: 7/31/2012 [Member] Starter | Points: 25

Up
0
Down
select ProductID,BrandID from Catalog.Product
where BrandID='0'

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

Posted by: CGN007 on: 7/31/2012 [Member] Silver | Points: 25

Up
0
Down
select ProductID,BrandID from Catalog.Product where BrandID='0' 


What about this query,that posted about by Vijayakumarp...?


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

Posted by: Sf_Hussain786 on: 7/31/2012 [Member] Starter | Points: 25

Up
0
Down
0 (zero) is also a bring id , when i am writing BrandID='-' (dashed) so why are those record return whose Brand ID is 0 , otherwise brand id is 0 is other.


sf_hussain786

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

Posted by: Sf_Hussain786 on: 7/31/2012 [Member] Starter | Points: 25

Up
0
Down
The Question is this,
this query return 0 record with the brandID="-"
Why this query return those records whose brand id is zero

sf_hussain786

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

Posted by: CGN007 on: 7/31/2012 [Member] Silver | Points: 25

Up
0
Down
Can you share some sample data..?

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

Posted by: CGN007 on: 7/31/2012 [Member] Silver | Points: 25

Up
0
Down
I think Pandians explained it nicely...
Hope it solves your problem...

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

Posted by: CGN007 on: 7/31/2012 [Member] Silver | Points: 25

Up
0
Down
Please share your comments...

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

Posted by: CGN007 on: 7/31/2012 [Member] Silver | Points: 25

Up
0
Down
Mark as answer if it helps...,That motivates...!!!

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

Posted by: Sf_Hussain786 on: 8/1/2012 [Member] Starter | Points: 25

Up
0
Down
Thank You Pandians , you solve my problem, thank you very much


sf_hussain786

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

Login to post response