Baanboard.com

Go Back   Baanboard.com > Forum > Baan Quick Support: Functional & Technical > Tools Development

Retirement Notice

Baanboard is shutting down on 31-dec-2023. See: http://www.baanboard.com/baanboard/showthread.php?t=76043


User login

Frontpage Sponsor

Main

Poll
What do you expect from your SI Implementation partner for the success of ERP implementation.
Bring best practices - Not to offer more CR's Leveraging standard functions
20%
Need more honesty to work with the Users until their processes are fully mapped & Users are trained
40%
Focus on process automation/ integrations/ Real time data/ BI analytics
13%
Stick to basics
27%
Total votes: 15

Reference Content

Reply
 
Thread Tools Display Modes
  #1  
Old 27th January 2023, 00:46
ajm1811 ajm1811 is offline
Junior Member
 
Join Date: Feb 2015
Posts: 7
ajm1811 is on a distinguished road
Baan: LNCE - DB: AWS - OS: Windows 11
Convert string to number in SQL query
Baan: Infor ERP 10.7
C/S: None/Unknown

Good evening tools people.

I'm trying to query a table on a string value but I want to treat it as numerical so I can select the correct range of records. At the moment it would select records where the value was greater than 960 for example, it's also selecting records where the value is 98.

Is there a way to process that value as numeric in my query? I've searched these forums and found something I thought might help which led me to the below but the compiler doesn't like it generating a type mismatch error.

Code:
long    v_wfid

select 	ttocm999.toid, CAST(ttocm999.wfid AS INTEGER) :v_wfid
	from	ttocm999 for update
	where	ttocm999.comp between :comp.from and :comp.to and
		ttocm999.codt between :codt.from and :codt.to and
		:v_wfid between :wfid.from and :wfid.to
	selectdo
		dal.destroy.object("ttocm999")
		commit.transaction()
	endselect
this one compiles but then I get a runtime error

Code:
select 	ttocm999.toid
	from	ttocm999 for update
	where	ttocm999.comp between :comp.from and :comp.to and
		ttocm999.codt between :codt.from and :codt.to and
		CAST(ttocm999.wfid AS INTEGER) between :wfid.from and :wfid.to
	selectdo
		dal.destroy.object("ttocm999")
		commit.transaction()
	endselect
Any help you can give would be much appreciated.
Reply With Quote
  #2  
Old 28th January 2023, 13:56
bdittmar's Avatar
bdittmar bdittmar is offline
Guru
 
Join Date: Apr 2002
Posts: 1,982
bdittmar will become famous soon enough
Baan: 2.2/3.1/4c4/LN6.1 FP6/FP9/HiDox Tools 10.7/D.3 - DB: tbase, ms-sql7, oracle10gV1, 11g, 12c, 19c - OS: HP-UX, W2K3, SLES, RHLE
Cast

I'm trying to query a table on a string value but I want to treat it as numerical so I can select the correct range of records.
At the moment it would select records where the value was greater than 960 for example, it's also selecting records where the value is 98.

Is there a way to process that value as numeric in my query? I've searched the forums and found something I thought might help which led me to the below but the compiler doesn't like it generating a type mismatch error.

Code:
CAST expression
With the CAST expression you can assign a type to a parameter. 

Syntax
<cast expression>
    ::= CAST ( Parameter AS <parameter cast type> )

<parameter cast type>
    ::= INTEGER | REAL | DATE | TIMESTAMP | STRING | RAW
Syntactical restrictions
The value of Parameter is restricted to the name of a column. A syntax error will result when any other type of expression is used. 

Semantics
The cast operator assigns the type <parameter cast type> to the <parameter>. The cast expression itself will also be of type <parameter cast type>. 

Examples
The following CAST expression assigns the type integer to the parameter param. 

CAST ( :param AS INTEGER )
The following CAST expression assigns the type raw to the parameter param. 

CAST ( :param AS RAW )
Resolving type conflicts on parameters
The cast operator is used to properly type parameters in case of ambiguities or in case of possible type conflicts. 

In the following example, both param1 and param2 cannot be typed, because each type is comparable to itself. 

:param1 = :param2
This problem can be resolved using the CAST expression.

:param1 = CAST( :param2 AS STRING )
In the following example the first comparison types param as date, while the second comparison types it as real. 

:param = hiredate  or  :param = 0
Using the CAST expression this can be resolved.

:param = hiredate  or  CAST( :param AS DATE ) = 0
this one compiles but then I get a runtime error

Regards
__________________
//Bernd
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming Question mr_suleyman Tools Development 37 11th November 2016 09:14
time conversion randeep Distribution, Transportation & Warehousing 3 19th December 2011 12:30
bshell received SIGTERM manojsharma Tools Development 11 5th June 2008 10:22
Maintain Replenishment Orders pedromrs AFS/DDC/OLE: Function servers 11 13th January 2007 09:32


All times are GMT +2. The time now is 01:14.


©2001-2023 - Baanboard.com - Baanforums.com