Solved

Coldfusion varchar to integer

Posted on 2007-03-28
2
719 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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

615 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