|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Concatenated in Sql StatementI 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? 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? 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? > > > 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? 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 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? |
|||||||||||||||||||||||