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 |
|
Eagle_f90
Constraint Violating Yak Guru
424 Posts |
Posted - 2011-11-13 : 19:08:54
|
| I need help figuring out how to go about combining two columns into one based on the value in a third column and I am not sure if I need to do this in a proc or can it be done in a view? Frist the combination issue, I have 3 columns named FirstName (varchar), LastName (varchar), and DisplayLast (bit). What I want to do is if the value of DisaplyLast = true then do a simple combind of the FirstName and LastName but if the value is false I want to add the First letter in LastName to the end of the full Value of FirstName. I.E if false then display John D. but if true then display John Doe.I am not sure if this would be best to do in a proc that my ASP.Net site calls and gets the data or if I can do it up in a view. I would like to do a view if possible as that will be easier for me to work with. I am a beginner when it comes to SQL and ASP.Net-- If I get used to envying others...Those things about my self I pride will slowly fade away.-Stellvia |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-11-13 : 19:16:23
|
| select FirstName + ' ' + case when DisplayLast = 1 then LastName else left(LasteName,1) + ',' endfrom tbl==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-14 : 00:21:36
|
| [code]select FirstName + ' ' + left(LastName,~DisplayLast)+ replicate(LastName,DisplayLast)from tbl[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|