Home All Groups Group Topic Archive Search About

Concatenated in Sql Statement

Author
9 Sep 2005 3:01 PM
jnorton
I have a tble with a field named product_id I have another field named image.
I would like to run a SQL stament that takes the data in the product_id
field and populates the image field and adds .jpg to the end. The image field
data then should look like product_id.jpg. Can this be done in SQL or di I
need to write a php script to do this?

Author
9 Sep 2005 3:09 PM
John 3:16
Update [YourTable] set Image = product_id + '.jpg'
hth,
bob mcclellan


Show quote
"jnorton" <jnor***@discussions.microsoft.com> wrote in message
news:16DB05F7-86C2-4D41-9544-576922DF2041@microsoft.com...
>I have a tble with a field named product_id I have another field named
>image.
> I would like to run a SQL stament that takes the data in the product_id
> field and populates the image field and adds .jpg to the end. The image
> field
> data then should look like product_id.jpg. Can this be done in SQL or di I
> need to write a php script to do this?
Author
9 Sep 2005 3:35 PM
R.D
oops
if  product_id  is numariic type then

Update [YourTable] set Image = cast( product_id as varchar(50)) + '.jpg'

Regards
R.D

Show quote
"John 3:16" wrote:

> Update [YourTable] set Image = product_id + '.jpg'
> hth,
> bob mcclellan
>
>
> "jnorton" <jnor***@discussions.microsoft.com> wrote in message
> news:16DB05F7-86C2-4D41-9544-576922DF2041@microsoft.com...
> >I have a tble with a field named product_id I have another field named
> >image.
> > I would like to run a SQL stament that takes the data in the product_id
> > field and populates the image field and adds .jpg to the end. The image
> > field
> > data then should look like product_id.jpg. Can this be done in SQL or di I
> > need to write a php script to do this?
>
>
>
Author
9 Sep 2005 3:44 PM
jnorton
It updated the image with the product_id but not the jpg

Show quote
"jnorton" wrote:

> I have a tble with a field named product_id I have another field named image.
> I would like to run a SQL stament that takes the data in the product_id
> field and populates the image field and adds .jpg to the end. The image field
> data then should look like product_id.jpg. Can this be done in SQL or di I
> need to write a php script to do this?
Author
9 Sep 2005 4:26 PM
Anith Sen
You may want to consider not to use another column just for a concatenated
string. In most scenarios, you can get the name by concatenating during data
retrieval.

Another option is to use a computed column like:

CREATE TABLE tbl (
    col INT ...
    new_col AS CAST( col AS VARCHAR ) + '.jpg'
    .. );

--
Anith
Author
10 Sep 2005 8:16 AM
R.D
Jnortaon
check the image datatype size to see that it fits
Regards
R.D

Show quote
"jnorton" wrote:

> It updated the image with the product_id but not the jpg
>
> "jnorton" wrote:
>
> > I have a tble with a field named product_id I have another field named image.
> > I would like to run a SQL stament that takes the data in the product_id
> > field and populates the image field and adds .jpg to the end. The image field
> > data then should look like product_id.jpg. Can this be done in SQL or di I
> > need to write a php script to do this?

AddThis Social Bookmark Button