September 24, 2012 at 6:43 am
Hi,
i have a table with columns
ID
F_Name
L_name
Full_Name
my requirement is when user inserts id, F_name, L_name
using trigger - concatenate F_Name + Lname and update in Full_Name column.
it should occur when insert / update happens
Please help me....
September 24, 2012 at 6:50 am
Rather than a trigger, can you change the table so that Full_Name is a calculated column?
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537September 24, 2012 at 8:22 am
Mark-101232 (9/24/2012)
Rather than a trigger, can you change the table so that Full_Name is a calculated column?
+1
A calculated column is far better here than a trigger for a number of reasons.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 24, 2012 at 9:11 am
Agreed.
For example:
ALTER TABLE dbo.tablename
DROP COLUMN Full_Name;
ALTER TABLE dbo.tablename
ADD Full_Name AS CAST(ISNULL(F_Name + ' ', '') + ISNULL(Lname, '') AS varchar(100))
-- change 100 to whatever max length you want for the column
SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.
September 24, 2012 at 2:13 pm
ScottPletcher (9/24/2012)
Agreed.For example:
ALTER TABLE dbo.tablename
DROP COLUMN Full_Name;
ALTER TABLE dbo.tablename
ADD Full_Name AS CAST(ISNULL(F_Name + ' ', '') + ISNULL(Lname, '') AS varchar(100))
-- change 100 to whatever max length you want for the column
It would take a little more space but I recommend adding the PERSISTED hint.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 24, 2012 at 5:17 pm
Jeff Moden (9/24/2012)
It would take a little more space but I recommend adding the PERSISTED hint.
For me, it depends, mostly on how and/or how often the full_name was used.
SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply