Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cstr within sql query...

Status
Not open for further replies.

A1Pat

IS-IT--Management
Jun 7, 2004
454
0
0
US
Hi all,

I'm trying to get data using such query:

sql = "SELECT a.ShortName, a.ShortDesc, a.ImageFileName, a.ProductID " _
& "FROM tblProducts a, tblProductType b " _
& " WHERE b.ProdTypeID = '43' " _
& " AND a.Hot = 1" _
& " AND CSTR(a.ProdTypeID) = b.ProdTypeID "


The problem is CSTR which is not usable in SQL, does anyone know how to fix that? Thanks!!!
 
I'm assuming SQL SERVER?

You want to use CAST or CONVERT

CONVERT(CHAR(n),a.ProdTypeID)
where n is the length. Optionally, use varchar.

But why do you have to convert it to a string; aren't both b.ProdTypeID and a.ProdTypeID integers?

sql = "SELECT a.ShortName, a.ShortDesc, a.ImageFileName, a.ProductID " _
& "FROM tblProducts a, tblProductType b " _
& " WHERE b.ProdTypeID = 43 " _
& " AND a.Hot = 1" _
& " AND a.ProdTypeID = b.ProdTypeID
 
Code:
ql = "SELECT a.ShortName, a.ShortDesc, a.ImageFileName, a.ProductID " _
                    & "FROM tblProducts as a, tblProductType as b " _
                    & "        WHERE b.ProdTypeID = '43' " _
                    & "        AND a.Hot = 1" _
                    & "        AND a.ProdTypeID = b.ProdTypeID "

try that.

www.sitesd.com
ASP WEB DEVELOPMENT
 
Just removing the CSTR won't help if the problem is that tblProductType.ProdTypeID is a string instead of an integer. As Travis suggested, you do indeed need CAST or CONVERT if that's your problem (though you may be better off changing the second one to an integer instead of the the first one into a string, since integer comparisons are much faster for the database than string comparisons).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top