CAST to a string 
Author Message
 CAST to a string
I am sure I will sound like an idiot for asking, but here goes.  How do you
convert a field in a DB2 SQL statement to be a string?  I have looked
through the manual 10 times, but I can't find the function.

If I could use vb syntax in SQL  it would look like this:

insert into tbl1(field1)
select CSTR(fieldX) from tbl2

THanks,  Tom



Fri, 02 May 2003 03:00:00 GMT
 CAST to a string

Hi Tom,

There are 2 ways to cast in SQL:

1) <cast_function>( <expression> )
For example, this SQL statement uses the cast function "CHAR" on the expression
1 to return the number 1 as a fixed length string:
    values CHAR(1);

2) CAST ( <expression> AS <data-type>)
For example:
    values CAST( 1 AS CHAR );
This kind of cast can also take NULL as the expression argument.

Check out the SQL Refrence for more details.

Hope this helps,
David.

Quote:

> I am sure I will sound like an idiot for asking, but here goes.  How do you
> convert a field in a DB2 SQL statement to be a string?  I have looked
> through the manual 10 times, but I can't find the function.

> If I could use vb syntax in SQL  it would look like this:

> insert into tbl1(field1)
> select CSTR(fieldX) from tbl2

> THanks,  Tom



Sat, 03 May 2003 03:00:00 GMT
 CAST to a string
Thanks, that will do the trick.
Tom


Quote:
> Hi Tom,

> There are 2 ways to cast in SQL:

> 1) <cast_function>( <expression> )
> For example, this SQL statement uses the cast function "CHAR" on the
expression
> 1 to return the number 1 as a fixed length string:
>     values CHAR(1);

> 2) CAST ( <expression> AS <data-type>)
> For example:
>     values CAST( 1 AS CHAR );
> This kind of cast can also take NULL as the expression argument.

> Check out the SQL Refrence for more details.

> Hope this helps,
> David.


> > I am sure I will sound like an idiot for asking, but here goes.  How do
you
> > convert a field in a DB2 SQL statement to be a string?  I have looked
> > through the manual 10 times, but I can't find the function.

> > If I could use vb syntax in SQL  it would look like this:

> > insert into tbl1(field1)
> > select CSTR(fieldX) from tbl2

> > THanks,  Tom



Sat, 03 May 2003 03:00:00 GMT
 CAST to a string

I think it the equivalent of CSTR in ANSI-92 SQL is CHAR()

Bill
Programmer/Analyst
Insituform Technologies, Inc.
(636) 530-2869



                                         cc:                                                                  
                    11/13/2000           Subject:     CAST to a string                                        
                    06:44 PM                                                                                  
                    Please                                                                                    
                    respond to                                                                                
                    comp.database                                                                            
                    s.ibm-db2                                                                                

I am sure I will sound like an idiot for asking, but here goes.  How do you
convert a field in a DB2 SQL statement to be a string?  I have looked
through the manual 10 times, but I can't find the function.

If I could use vb syntax in SQL  it would look like this:

insert into tbl1(field1)
select CSTR(fieldX) from tbl2

THanks,  Tom

 Sent via Deja.com http://www.deja.com/
 Before you buy.



Mon, 05 May 2003 03:00:00 GMT
 CAST to a string
If c1 was an integer (for instance), you;d code something like:

select cast(c1 as char(10)) from t1;

--
Richard Mitch Mitchell
Senior Database Administrator
IBM Certified Solutions Expert - DB2 UDB v6.1 Database Administration
for UNIX, Windows and OS/2

Fracta Networks

Quote:

> I think it the equivalent of CSTR in ANSI-92 SQL is CHAR()

> Bill
> Programmer/Analyst
> Insituform Technologies, Inc.
> (636) 530-2869


Quote:
>                     mail.com             To:     comp.databases.ibm-


Quote:

cc:
>                     11/13/2000           Subject:     CAST to a
string
>                     06:44

PM

Please

Quote:
>                     respond

to

comp.database

Quote:
>                     s.ibm-

db2

Quote:

> I am sure I will sound like an idiot for asking, but here goes.  How
do you
> convert a field in a DB2 SQL statement to be a string?  I have looked
> through the manual 10 times, but I can't find the function.

> If I could use vb syntax in SQL  it would look like this:

> insert into tbl1(field1)
> select CSTR(fieldX) from tbl2

> THanks,  Tom

>  Sent via Deja.com http://www.deja.com/
>  Before you buy.

--
Richard Mitch Mitchell
Senior Database Administrator
IBM Certified Solutions Expert - DB2 UDB v6.1 Database Administration
for UNIX, Windows and OS/2

Fracta Networks

Sent via Deja.com http://www.deja.com/
Before you buy.



Tue, 06 May 2003 08:10:05 GMT
 
 [ 5 post ] 

 Relevant Pages 

1. CAST and datetime string

2. How to cast / convert a string to uniqueidentifier?

3. cast integer to string

4. Casting Longint to String in Query ?

5. Casting/ Converting a String...

6. CASTING/ CONVERTING A STRING...

7. implicit casting of uniqueidentifier to string

8. Cast String to Int

9. string cast/compare broken?

10. casting text string s as ttables / tqueries

11. Cast String as date

12. casting as string truncs my number


 
Powered by phpBB® Forum Software