Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
scholin
Yak Posting Veteran
56 Posts |
Posted - 2010-02-09 : 00:17:46
|
| I am not sure if I need a calculated field, a Trigger or a Procedure and I am not sure if I should use Case or If/Then statements but here is what I am trying to accomplish.I need a function that will look up lets say 4 varchar fields: muscle1, muscle2, muscle3, muscle4 (there will actually be about 10 more). These fields are in a table called dbo.muscles.I need this function to first see if the each field is not blank. If it is not blank, then it needs to add it to calculated field called muscle_string, add a comma and space .. . . thus making a long string properly formatted IDEALLY like the following example output: "Opponens Policis, Deltoid Muscle, Tricep Muscle and Trapezuis Muscle."This is all in the same table. I would just like to have this calculated in SQL and availbe as field within dbo.muscles.What is the best way/syntax etc to accomplish this?Thank you for any help! |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
scholin
Yak Posting Veteran
56 Posts |
Posted - 2010-02-10 : 08:01:54
|
| Thank you for responding KH - I am using sql 2008 standard. This is working with just one table. People will enter various muscles from a web site into this table and I need to create a function that will output a concatenated string (ideally properly formatted).I know there are several steps here to look for the fields with data and then to add them to a string with commas and ideally and "and" before the last word in the list.Just not sure how to set this up. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-02-10 : 08:20:39
|
have you take a look at the links, since you are using SQL 2008, you can use the method describe here : concatenate records without UDF KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-10 : 08:21:00
|
quote: Originally posted by scholin Thank you for responding KH - I am using sql 2008 standard. This is working with just one table. People will enter various muscles from a web site into this table and I need to create a function that will output a concatenated string (ideally properly formatted).I know there are several steps here to look for the fields with data and then to add them to a string with commas and ideally and "and" before the last word in the list.Just not sure how to set this up.
do you mean you need to concatenate values from multiple tables together?------------------------------------------------------------------------------------------------------SQL Server MVP |
 |
|
|
|
|
|
|
|