dbTalk Databases Forums  

CONVERT or CAST?

comp.databases.mysql comp.databases.mysql


Discuss CONVERT or CAST? in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mike Jacoubowsky
 
Posts: n/a

Default CONVERT or CAST? - 03-04-2010 , 10:45 PM






I've got an SQL query that asks for input and returns info (big surprise
there!). Trouble is, the query gets messed up when you give it
completely-numeric input. It's fine with alpha-numeric. The line causing the
trouble is below-
.....
AND Products.Description like '%' +<<Description>> + '%'
.....

I've been trying various ways of using CONVERT or CAST to make sure the
input ends up being character, not numeric, but can't quite get a handle on
it. Is this really something simple or is there a good reason (besides me
being inept at this sort of thing) for why I can't figure this one out? The
entire script is shown below.

Thanks-

--Mike Jacoubowsky
Chain Reaction Bicycles
www.ChainReaction.com
Redwood City & Los Altos, CA USA


SELECT TOP 1 Locations.ID,
'**SKU' AS SKU,
'Description'AS Description,
RIGHT('QOH',6) AS QOH,
'Total Units'
FROM Locations
UNION
SELECT Products.ID,
Products.[Store UPC] AS SKU,
Products.Description,
CONVERT(VARCHAR, Products.Quantity),
CONVERT(VARCHAR, SUM(SalesItems.QUantity))
FROM Sales, SalesItems, Products
WHERE Sales.Hide = 0
AND SUBSTRING(CONVERT(VARCHAR, Sales.FinishDate, 112), 1,6) <=
SUBSTRING(CONVERT(VARCHAR,
GETDATE(), 112), 1,6)
AND SUBSTRING(CONVERT(VARCHAR, Sales.FinishDate, 112), 1,6) >
SUBSTRING(CONVERT(VARCHAR,
DATEADD(YEAR, -1, GETDATE()),112), 1,6)
AND Sales.ID = SalesItems.SalesID
AND SalesItems.Hide = 0
AND SalesItems.ProductID = Products.ID
AND Products.Brand like '%' +<<Brand>>+ '%'
AND Products.Description like '%' +<<Description>> + '%'
GROUP BY Products.ID,
Products.[Store UPC],
Products.Description,
Products.Quantity
ORDER BY SKU,
Description

Reply With Quote
  #2  
Old   
Lennart
 
Posts: n/a

Default Re: CONVERT or CAST? - 03-05-2010 , 12:05 AM






On 5 mar, 04:45, "Mike Jacoubowsky" <Mi... (AT) ChainReaction (DOT) com> wrote:
[...]
Quote:
....
AND Products.Description like '%' +<<Description>> + '%'
....
Have you tried using a prepared statement? As a side note, the sql
concat operator is ||, not +, see PIPES_AS_CONCAT


/Lennart

[...]

Reply With Quote
  #3  
Old   
Mike Jacoubowsky
 
Posts: n/a

Default Re: CONVERT or CAST? - 03-05-2010 , 12:23 AM



"Lennart" <erik.lennart.jonsson (AT) gmail (DOT) com> wrote

Quote:
On 5 mar, 04:45, "Mike Jacoubowsky" <Mi... (AT) ChainReaction (DOT) com> wrote:
[...]
....
AND Products.Description like '%' +<<Description>> + '%'
....

Have you tried using a prepared statement? As a side note, the sql
concat operator is ||, not +, see PIPES_AS_CONCAT


/Lennart

[...]
Near as I can tell, I'm dealing with is an sql "window" into an application
built with VB6. That could account for the non-standard conventions seen in
the script I listed. I tried using the standard for piping but that throws
out an error message.

From what I've read of SQL, there is no standard convention for user input
within brackets, as seen in the line I referenced.

Thanks-

--Mike Jacoubowsky
Chain Reaction Bicycles
www.ChainReaction.com
Redwood City & Los Altos, CA USA

Reply With Quote
  #4  
Old   
Lennart
 
Posts: n/a

Default Re: CONVERT or CAST? - 03-05-2010 , 04:43 AM



On 5 mar, 06:23, "Mike Jacoubowsky" <Mi... (AT) ChainReaction (DOT) com> wrote:
Quote:
"Lennart" <erik.lennart.jons... (AT) gmail (DOT) com> wrote in message

news:e77cafcf-ad05-4a9e-a4de-1efbbe5914b8 (AT) q16g2000yqq (DOT) googlegroups.com...

On 5 mar, 04:45, "Mike Jacoubowsky" <Mi... (AT) ChainReaction (DOT) com> wrote:
[...]
....
AND Products.Description like '%' +<<Description>> + '%'
....

Have you tried using a prepared statement? As a side note, the sql
concat operator is ||, not +, see *PIPES_AS_CONCAT

/Lennart

[...]

Near as I can tell, I'm dealing with is an sql "window" into an application
built with VB6. That could account for the non-standard conventions seen in
the script I listed. I tried using the standard for piping but that throws
out an error message.

From what I've read of SQL, there is no standard convention for user input
within brackets, as seen in the line I referenced.

There is no such thing as user input in sql. That is handled by the
application and a query is constructed and sent to the dbms. But I
think your problem lies in the applications layer, so perhaps you
should address this issue in a VB6 forum.


/Lennart

[...]

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.