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 |
|
giovi2002
Starting Member
46 Posts |
Posted - 2005-08-14 : 16:26:46
|
I would like to concatenate all my fields in the table per row after the insert into a field called 'mergefield'. Examplefld1 fld2 fld 3 mergefieldaaa bb <null> aaabbaa <null> ee aaeeetcProblem is when using standard sql select fld1+fld2+fld3 from table rows with one null field will disappear. I've tried SET CONCAT_NULL_YIELDS_NULL { ON | OFF } in my stored procedure but that didn't help.Do you have an easy workaround without overcoding with if statements or case statements? |
|
|
giovi2002
Starting Member
46 Posts |
Posted - 2005-08-14 : 16:35:44
|
| Oops think i found it.Executed this in query analyzerSET CONCAT_NULL_YIELDS_NULL OFFselect lijnnummer, send_key,convert(varchar(4),lijnnummer)+convert(varchar(4),send_key) As expr1 from aantal_dagenFirst you see the two integers (lijnnummer, send)key) in the third column a varchar concatenation1 1 111 1 112 1 211 1 111 1 113 NULL 34 NULL 45 NULL 56 NULL 67 NULL 7 |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-08-14 : 17:48:45
|
| There's also the isNull functionBe One with the OptimizerTG |
 |
|
|
giovi2002
Starting Member
46 Posts |
Posted - 2005-08-15 : 03:13:26
|
| Yes the isnull function can be used with concatenation of two fields but not with three or more if i'm right. If one field would be null he will pick the first not nulled field instead of concatenation of the two not nulled fields |
 |
|
|
LarsG
Constraint Violating Yak Guru
284 Posts |
Posted - 2005-08-15 : 04:01:13
|
| [code]coalesce(column1,'') + coalesce(column2,'') + coalesce(column3,'')[/code]Don't use isnull, it is non-standard. Table have columns, not fields. |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-08-15 : 08:25:07
|
| >>Don't use isnull, it is non-standardI've got no problem using sql server functions that aren't ansi-standards. Coalesce and isNull have different functionalities. Coalesce can take multiple expressions and return the first non-null value. That is very usefull in some situations. IsNull only takes 2 expressions and supports a datatype precedence so that the second expression returns the same datatype that the first expression evaluates to. That is also very usefull (in other situations). Just make it your business to understand the benifits/limitationss of any functions you use.mhoBe One with the OptimizerTG |
 |
|
|
|
|
|