Sql convert Numeric to character

Sql convert Numeric to character

Postby Rick Lipkin » Fri Aug 29, 2014 3:06 pm

To All

I have successfully written a Sql script that takes the Sql Field [InvoiceNumber] Integer and converted it to character with this script and it works :

Code: Select all  Expand view

cSql := "Select str(InvoiceNumber) as InvoiceNumber, "
cSql += "CustomerId "
cSql += "From Billing"


oRsInv := TOleAuto():New( "ADODB.Recordset" )
oRsInv:CursorType     := 1        // opendkeyset
oRsInv:CursorLocation := 3        // local cache
oRsInv:LockType       := 3        // lockoportunistic

TRY
   oRsInv:Open( cSQL,xCONNECT )
CATCH oErr
   MsgInfo( "Error in Opening Invoice Number table" )
   oRsCust:Close()
   oRsBill:Close()
   _CleanUP()
   oDlg:End()
   RETURN(.F.)
END TRY

xbrowse(oRsInv )

oRsInv:Filter := "InvoiceNumber = '10'"
xbrowse( oRsInv )

 


Image
As you can see .. [InvoiceNumber] has been converted to Charactor .. however, creating a filter on the converted [InvoiceNumber] fails ???

Image

Any Ideas ?
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2642
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Sql convert Numeric to character ( solved )

Postby Rick Lipkin » Fri Aug 29, 2014 3:35 pm

To All

With a bit more research I found this Sql function cStr() to give me the correct results in Ms Access ..

http://bytes.com/topic/access/answers/2 ... ger-string

Code: Select all  Expand view

cSql := "Select cStr([InvoiceNumber]) as InvoiceNumber, " // as Invoicenumber, "
cSql += "CustomerId "
cSql += "From Billing"
 


I do know know if cStr() is compatible with Sql Server ?

Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2642
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Sql convert Numeric to character

Postby Biel EA6DD » Mon Sep 01, 2014 6:40 am

STR ( float_expression [ , length [ , decimal ] ] )

I thing the default length returned by STR is 10. Try to specify a lengt.

Code: Select all  Expand view
Select str(InvoiceNumber,2) as InvoiceNumber, "
...
oRsInv:Filter := "
InvoiceNumber = '10'"

Saludos desde Mallorca
Biel Maimó
http://bielsys.blogspot.com/
User avatar
Biel EA6DD
 
Posts: 682
Joined: Tue Feb 14, 2006 9:48 am
Location: Mallorca


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 70 guests