Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
Trigger to concatenate two columns and update...
Trigger to concatenate two columns and update in new column
Rate Topic
Display Mode
Topic Options
Author
Message
Minnu
Minnu
Posted Monday, September 24, 2012 6:43 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Today @ 7:30 AM
Points: 124,
Visits: 371
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....
Post #1363458
Mark-101232
Mark-101232
Posted Monday, September 24, 2012 6:50 AM
SSCommitted
Group: General Forum Members
Last Login: Today @ 9:53 AM
Points: 1,501,
Visits: 18,208
Rather than a trigger, can you change the table so that Full_Name is a calculated column?
____________________________________________________
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537
Never approach a goat from the front, a horse from the rear, or a fool from any direction.
Post #1363460
Sean Lange
Sean Lange
Posted Monday, September 24, 2012 8:22 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 1:17 PM
Points: 8,641,
Visits: 8,273
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 Moden's
splitter
.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Post #1363518
ScottPletcher
ScottPletcher
Posted Monday, September 24, 2012 9:11 AM
Ten Centuries
Group: General Forum Members
Last Login: 2 days ago @ 3:56 PM
Points: 1,324,
Visits: 1,778
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)
One man with courage makes a majority. Andrew Jackson
Post #1363560
Jeff Moden
Jeff Moden
Posted Monday, September 24, 2012 2:13 PM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 4:51 PM
Points: 32,923,
Visits: 26,811
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
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1363716
ScottPletcher
ScottPletcher
Posted Monday, September 24, 2012 5:17 PM
Ten Centuries
Group: General Forum Members
Last Login: 2 days ago @ 3:56 PM
Points: 1,324,
Visits: 1,778
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)
One man with courage makes a majority. Andrew Jackson
Post #1363750
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.