pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
convert to a string
6+ messages / 3 participants
[nested] [flat]

* convert to a string
@ 2007-03-06 13:42  Shavonne Marietta Wijesinghe <shavonne.marietta@studioform.it>
  0 siblings, 2 replies; 6+ messages in thread

From: Shavonne Marietta Wijesinghe @ 2007-03-06 13:42 UTC (permalink / raw)
  To: pgsql-sql

Hello 

i have a column N_GEN in postgreSql defined as text. In this coloumn i insert a number 10

N_GEN (text) = 10


on error resume next
  Set oRs = oConn.Execute("SELECT N_GEN FROM MyTable ORDER BY N_GEN DESC")
  If err <> 0 then 'If table not found
   GetFieldValue = "1"
  else
   GetFieldValue = oRs("N_GEN") + 1
  End If

But it doesn't add the 1 to my N_GEN
How can i set the Recordset to convert the string to a number and then add 1 to it??

Shavonne Wijesinghe
http://www.studioform.it

 

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: convert to a string
@ 2007-03-06 13:54  Bart Degryse <Bart.Degryse@indicator.be>
  parent: Shavonne Marietta Wijesinghe <shavonne.marietta@studioform.it>
  1 sibling, 1 reply; 6+ messages in thread

From: Bart Degryse @ 2007-03-06 13:54 UTC (permalink / raw)
  To: pgsql-sql

I assume GetFieldValue is the name of a VB function or property get?
 
Try either
  Set oRs = oConn.Execute("SELECT N_GEN::int FROM MyTable ORDER BY N_GEN DESC")
or
   GetFieldValue = cint(oRs("N_GEN")) + 1
or
   GetFieldValue = clng(oRs("N_GEN")) + 1

In the last two cases make sure that the function or property get returns an int or long
Also remember that if oRs("N_GEN") is NULL the sum will also be NULL

>>> "Shavonne Marietta Wijesinghe" <shavonne.marietta@studioform.it> 2007-03-06 14:42 >>>
Hello 

i have a column N_GEN in postgreSql defined as text. In this coloumn i insert a number 10

N_GEN (text) = 10 
 

 

on error resume next
  Set oRs = oConn.Execute("SELECT N_GEN FROM MyTable ORDER BY N_GEN DESC")
  If err <> 0 then 'If table not found
   GetFieldValue = "1"
  else
   GetFieldValue = oRs("N_GEN") + 1
  End If
 
But it doesn't add the 1 to my N_GEN
How can i set the Recordset to convert the string to a number and then add 1 to it??
 
Shavonne Wijesinghe
http://www.studioform.it ( http://www.studioform.it/ )
 

 

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: convert to a string
@ 2007-03-06 13:56  A. Kretschmer <andreas.kretschmer@schollglas.com>
  parent: Shavonne Marietta Wijesinghe <shavonne.marietta@studioform.it>
  1 sibling, 0 replies; 6+ messages in thread

From: A. Kretschmer @ 2007-03-06 13:56 UTC (permalink / raw)
  To: pgsql-sql

am  Tue, dem 06.03.2007, um 14:42:53 +0100 mailte Shavonne Marietta Wijesinghe folgendes:
> Hello
> 
> i have a column N_GEN in postgreSql defined as text. In this coloumn i insert a
> number 10

Why do you store numbers as text?


> 
> N_GEN (text) = 10
>  
>  
> on error resume next
>   Set oRs = oConn.Execute("SELECT N_GEN FROM MyTable ORDER BY N_GEN DESC")
>  
> But it doesn't add the 1 to my N_GEN

You can't add a number to a string.


> How can i set the Recordset to convert the string to a number and then add 1 to
> it??

You can try to cast it to int:

test=# select '10'::text;
 text
------
 10
(1 row)

test=*# select '10'::text::int;
 int4
------
   10
(1 row)


In your Query, change 'SELECT N_GEN FROM' to 'SELECT N_GEN::int FROM'.


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: convert to a string
@ 2007-03-06 14:32  Shavonne Marietta Wijesinghe <shavonne.marietta@studioform.it>
  parent: Bart Degryse <Bart.Degryse@indicator.be>
  0 siblings, 1 reply; 6+ messages in thread

From: Shavonne Marietta Wijesinghe @ 2007-03-06 14:32 UTC (permalink / raw)
  To: pgsql-sql

when i try the 
set oRs = oConn.Execute("SELECT N_GEN::int FROM MyTable ORDER BY N_GEN DESC") 
it returns 1 and for the rest i doens't change. alsways 10
 :(
  ----- Original Message ----- 
  From: Bart Degryse 
  To: pgsql-sql@postgresql.org 
  Sent: Tuesday, March 06, 2007 2:54 PM
  Subject: Re: [SQL] convert to a string


  I assume GetFieldValue is the name of a VB function or property get?

  Try either
    Set oRs = oConn.Execute("SELECT N_GEN::int FROM MyTable ORDER BY N_GEN DESC")
  or
     GetFieldValue = cint(oRs("N_GEN")) + 1
  or
     GetFieldValue = clng(oRs("N_GEN")) + 1

  In the last two cases make sure that the function or property get returns an int or long
  Also remember that if oRs("N_GEN") is NULL the sum will also be NULL

  >>> "Shavonne Marietta Wijesinghe" <shavonne.marietta@studioform.it> 2007-03-06 14:42 >>>
  Hello 

  i have a column N_GEN in postgreSql defined as text. In this coloumn i insert a number 10

  N_GEN (text) = 10 


  on error resume next
    Set oRs = oConn.Execute("SELECT N_GEN FROM MyTable ORDER BY N_GEN DESC")
    If err <> 0 then 'If table not found
     GetFieldValue = "1"
    else
     GetFieldValue = oRs("N_GEN") + 1
    End If

  But it doesn't add the 1 to my N_GEN
  How can i set the Recordset to convert the string to a number and then add 1 to it??

  Shavonne Wijesinghe
  http://www.studioform.it


   

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: convert to a string
@ 2007-03-06 14:38  Bart Degryse <Bart.Degryse@indicator.be>
  parent: Shavonne Marietta Wijesinghe <shavonne.marietta@studioform.it>
  0 siblings, 0 replies; 6+ messages in thread

From: Bart Degryse @ 2007-03-06 14:38 UTC (permalink / raw)
  To: pgsql-sql; +Cc: Shavonne Marietta Wijesinghe <shavonne.marietta@studioform.it>

As Andreas already asked: do you really have a good reason to store numbers as text
If so, show us some more information: table definition, some table data, a complete (vb?) function/property get, ... anything that is directly involved.


>>> "Shavonne Marietta Wijesinghe" <shavonne.marietta@studioform.it> 2007-03-06 15:32 >>>
when i try the 
set oRs = oConn.Execute("SELECT N_GEN::int FROM MyTable ORDER BY N_GEN DESC") 
it returns 1 and for the rest i doens't change. alsways 10
 :(


----- Original Message ----- 
From: Bart Degryse ( mailto:Bart.Degryse@indicator.be ) 
To: pgsql-sql@postgresql.org 
Sent: Tuesday, March 06, 2007 2:54 PM
Subject: Re: [SQL] convert to a string

I assume GetFieldValue is the name of a VB function or property get?
 
Try either
  Set oRs = oConn.Execute("SELECT N_GEN::int FROM MyTable ORDER BY N_GEN DESC")
or
   GetFieldValue = cint(oRs("N_GEN")) + 1
or
   GetFieldValue = clng(oRs("N_GEN")) + 1

In the last two cases make sure that the function or property get returns an int or long
Also remember that if oRs("N_GEN") is NULL the sum will also be NULL

>>> "Shavonne Marietta Wijesinghe" <shavonne.marietta@studioform.it> 2007-03-06 14:42 >>>
Hello 

i have a column N_GEN in postgreSql defined as text. In this coloumn i insert a number 10

N_GEN (text) = 10 
 

 

on error resume next
  Set oRs = oConn.Execute("SELECT N_GEN FROM MyTable ORDER BY N_GEN DESC")
  If err <> 0 then 'If table not found
   GetFieldValue = "1"
  else
   GetFieldValue = oRs("N_GEN") + 1
  End If
 
But it doesn't add the 1 to my N_GEN
How can i set the Recordset to convert the string to a number and then add 1 to it??
 
Shavonne Wijesinghe
http://www.studioform.it ( http://www.studioform.it/ )
 

 

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: convert to a string
@ 2007-03-06 14:49  Shavonne Marietta Wijesinghe <shavonne.marietta@studioform.it>
  0 siblings, 0 replies; 6+ messages in thread

From: Shavonne Marietta Wijesinghe @ 2007-03-06 14:49 UTC (permalink / raw)
  To: pgsql-sql

i figured it out

Set oRs = oConn.Execute("SELECT N_GEN FROM " & MyTable & " ORDER BY N_GEN::INT DESC")

thanks to everyone
  ----- Original Message ----- 
  From: Shavonne Marietta Wijesinghe 
  To: pgsql-sql@postgresql.org 
  Sent: Tuesday, March 06, 2007 3:32 PM
  Subject: Re: [SQL] convert to a string


  when i try the 
  set oRs = oConn.Execute("SELECT N_GEN::int FROM MyTable ORDER BY N_GEN DESC") 
  it returns 1 and for the rest i doens't change. alsways 10
   :(
    ----- Original Message ----- 
    From: Bart Degryse 
    To: pgsql-sql@postgresql.org 
    Sent: Tuesday, March 06, 2007 2:54 PM
    Subject: Re: [SQL] convert to a string


    I assume GetFieldValue is the name of a VB function or property get?

    Try either
      Set oRs = oConn.Execute("SELECT N_GEN::int FROM MyTable ORDER BY N_GEN DESC")
    or
       GetFieldValue = cint(oRs("N_GEN")) + 1
    or
       GetFieldValue = clng(oRs("N_GEN")) + 1

    In the last two cases make sure that the function or property get returns an int or long
    Also remember that if oRs("N_GEN") is NULL the sum will also be NULL

    >>> "Shavonne Marietta Wijesinghe" <shavonne.marietta@studioform.it> 2007-03-06 14:42 >>>
    Hello 

    i have a column N_GEN in postgreSql defined as text. In this coloumn i insert a number 10

    N_GEN (text) = 10 


    on error resume next
      Set oRs = oConn.Execute("SELECT N_GEN FROM MyTable ORDER BY N_GEN DESC")
      If err <> 0 then 'If table not found
       GetFieldValue = "1"
      else
       GetFieldValue = oRs("N_GEN") + 1
      End If

    But it doesn't add the 1 to my N_GEN
    How can i set the Recordset to convert the string to a number and then add 1 to it??

    Shavonne Wijesinghe
    http://www.studioform.it


     

^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2007-03-06 14:49 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-03-06 13:42 convert to a string Shavonne Marietta Wijesinghe <shavonne.marietta@studioform.it>
2007-03-06 13:54 ` Bart Degryse <Bart.Degryse@indicator.be>
2007-03-06 14:32   ` Shavonne Marietta Wijesinghe <shavonne.marietta@studioform.it>
2007-03-06 14:38     ` Bart Degryse <Bart.Degryse@indicator.be>
2007-03-06 13:56 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
2007-03-06 14:49 Re: convert to a string Shavonne Marietta Wijesinghe <shavonne.marietta@studioform.it>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox