Solved

Coldfusion varchar to integer

Posted on 2007-03-28
2
718 Views
Last Modified: 2010-08-05
I am trying to convert a datatype of varchar to interger. The reason is I need the string to work using the sql between statement. I'm extracting results from a database and creating a total for each range. See code below

<cfparam name="sortby" default="Pub_Detail_Order_Date">
<cfif isDefined("url.sortby")>
      <cfset sortby = url.sortby>
</cfif>
<cfparam name="direction" default="DESC">
<cfif isDefined("url.direction")>
      <cfset direction = url.direction>
</cfif>
<cfquery datasource="#application.dsName#" username="#application.dsUserName#" password="#application.dsPassword#" name="forms">
SELECT *
FROM Pub_Details
            WHERE Pub_Detail_Title LIKE '%IMPRINTED - %'
                  Order BY #sortby# #direction#

</cfquery>

<cfquery dbtype="query" name="first_qry">
     SELECT * FROM forms WHERE Pub_Detail_Qty >= '0' and Pub_Detail_Qty <= '999'
</cfquery>
<cfquery dbtype="query" name="second_qry">
     SELECT * FROM forms WHERE Pub_Detail_Qty >= '1000' and Pub_Detail_Qty <= '1999'
</cfquery>
<cfquery dbtype="query" name="third_qry">
     SELECT * FROM forms WHERE Pub_Detail_Qty >= '2000'
</cfquery>

I get great results, except that I don't only get numbers 0 - 999 in the first query. 1500 shows up too. I am using MSSQL. The following code is what gets generated for the first query of a query:

Imprinting and Blank Orders Between 0 and 999
Date Qty Unit Cost Title Extended Cost
27-Jan-06 12:28 PM
 35
 .45
 IMPRINTED - PLUS MPN
 $15.75
 
27-Jan-06 05:23 PM
 250
 .45
 IMPRINTED - PLUS MPN
 $112.5
 
27-Jan-06 05:23 PM
 500
 .45
 IMPRINTED - PLUS SCHOOL CERTIFICATION
 $225
 
19-Oct-06 01:38 PM
 500
 .45
 IMPRINTED - STAFFORD MPN
 $225
 
19-Oct-06 01:31 PM
 500
 .45
 IMPRINTED - STAFFORD MPN
 $225
 
18-Jan-06 11:04 PM
 222
 .45
 IMPRINTED - PLUS MPN
 $99.9
 
18-Jan-06 11:03 PM
 222
 .45
 IMPRINTED - PLUS MPN
 $99.9
 
18-Jan-06 10:43 PM
 222
 .45
 IMPRINTED - PLUS MPN
 $99.9
 
18-Jan-06 10:24 PM
 150
 .45
 IMPRINTED - PLUS MPN
 $67.5
 
18-Jan-06 10:24 PM
 1500
 .45
 IMPRINTED - PLUS SCHOOL CERTIFICATION
 $675
 
02-Aug-06 12:27 PM
 5
 .45
 IMPRINTED - PLUS SCHOOL CERTIFICATION
 $2.25
 
0
Comment
Question by:asaworker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18810962
do NOT use quotes around numerical data/fields:

     SELECT * FROM forms WHERE Pub_Detail_Qty >= 0 and Pub_Detail_Qty <= 999

     SELECT * FROM forms WHERE Pub_Detail_Qty >=  1000 and Pub_Detail_Qty <=  1999

etc

hopefully, the field Pub_Details_Qty is of numerical data type, otherwise you should change that.
0
 

Author Comment

by:asaworker
ID: 18811153
Thanks angellll, I figured that might of been the root of the problem.
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question