Hi.
I want to a simple select query from Mssql db but its getting error. I wanna search this;
-------------------------------------
"Cisco IOS Software, s4444_rp Software (s4444_rp-ADVIPSERVICESK9-M), Version , RELEASE SOFTWARE (fc6) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2008 by Cisco Systems, Inc. Compiled Wed 16-Jan-09 12:12 by prod_rel"
-------------------------------------
So I am using this query;
-------------------------------------
SELECT * FROM Servers where SysDescr='Cisco IOS Software, s6523_rp Software (s6523_rp-ADVIPSERVICESK9-M), Version 12.2(33)SXH1, RELEASE SOFTWARE (fc3) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2008 by Cisco Systems, Inc. Compiled Wed 16-Jan-08 23:50 by prod_rel'
-------------------------------------
But its getting this error;
-------------------------------------
Msg 402, Level 16, State 1, Line 1
The data types text and varchar are incompatible in the equal to operator.
-------------------------------------
How may I search this?
Loading
VulpesPosted Dec 7, 2011, 9:50 AM
Unfortunately, SQL Server doesn't support the STRCMP function.
However, you could try casting the text column to varchar and then using the = operator:
SELECT * FROM Servers where CAST(SysDescr AS varchar) = 'Cisco IOS Software, s6523_rp Software (s6523_rp-ADVIPSERVICESK9-M), Version 12.2(33)SXH1, RELEASE SOFTWARE (fc3) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2008 by Cisco Systems, Inc. Compiled Wed 16-Jan-08 23:50 by prod_rel'
VulpesPosted Dec 8, 2011, 4:31 AM
Pravin MorePosted Dec 8, 2011, 2:00 AM
it means query is correct as it it giving result when you match other string....
you might be comparing unmatching string with column....
yokzuPosted Dec 8, 2011, 1:23 AM
yokzuPosted Dec 7, 2011, 9:31 AM
VulpesPosted Dec 7, 2011, 9:28 AM
yokzuPosted Dec 7, 2011, 9:01 AM
When I try like this, its working.
SELECT * FROM Servers where SysDescr LIKE '%Cisco IOS Software%' ---->ok
SELECT * FROM Nodes where SysDescr LIKE '%Cisco IOS Software, s6523_rp Software%' ----->ok
SELECT * FROM Nodes where SysDescr LIKE '%Cisco IOS Software, s6523_rp Software (s6523_rp-ADVIPSERVICESK9-M)%' ----->ok
SELECT * FROM Servers where SysDescr LIKE '%Compiled Wed 16-Jan-08 23:50 by prod_rel%' ---->ok
But when I try like below, all of them are getting no row. I tryed again and again but the result is same.
SELECT * FROM Nodes where SysDescr LIKE '%Cisco IOS Software, s6523_rp Software (s6523_rp-ADVIPSERVICESK9-M), Version 12.2(33)SXH1, RELEASE SOFTWARE (fc3) Technical%' ----> NOT OK
SELECT * FROM Nodes where SysDescr LIKE '%isco Systems, Inc. Compiled Wed 16-Jan-08 23:50 by prod_rel%' ----> NOT OK
SELECT * FROM Nodes where SysDescr LIKE '%Technical Support: http://www.cisco.com/techsupport Copyright%' ----> NOT OK
Pravin MorePosted Dec 7, 2011, 8:13 AM
like is working at my side. you might be comparing unmatching string with column....
for testing purpose check below one...........
SELECT * FROM Servers where SysDescr='%Cisco IOS Software%'
thanks,
Pravin.
yokzuPosted Dec 7, 2011, 7:57 AM
Pravin MorePosted Dec 7, 2011, 7:53 AM
you cannot use equal operator (=) on text datatype column .
so use 'like' instead......like below............
SELECT * FROM Servers where SysDescr like 'Cisco IOS Software, s6523_rp Software (s6523_rp-ADVIPSERVICESK9-M), Version 12.2(33)SXH1, RELEASE SOFTWARE (fc3) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2008 by Cisco Systems, Inc. Compiled Wed 16-Jan-08 23:50 by prod_rel'
Thanks,
Pravin.