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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Join tow column

Author  Topic 

atuljadhavnetafim
Starting Member

25 Posts

Posted - 2014-09-29 : 01:32:38
Dear expert

i have 6 table in SQL Server
and i have created one view and create single table by linking all the table,
now i want to join two column like
Column A and Column B = Column C
e.g
A B C
Atul Jadhav Atuljadhav
Vijay vijayvijay

in above exambe column A having firstName and Column B having second name and i want to join this two column in C column "atuljadhav"
and if column B is blank then it join A value tow times

please give me triger code as it is auto update column and every time (update, append, modify, delete) it should be update automatic

please help


Atul Jadhav

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2014-09-29 : 02:16:57
[CODE]CREATE TABLE TestConcat( A VARCHAR(100), B VARCHAR(100),C VARCHAR(200))
GO
CREATE TRIGGER Trg_TestConcat
ON TestConcat
FOR INSERT, UPDATE
AS
UPDATE TestConcat SET C=A+ISNULL(B, A)
GO

-- Test Trigger
insert into TestConcat( A, B)
SELECT 'Atul', 'Jadhav' union all
SELECT 'Vijay', NULL

SELECT * FROM TestConcat
[/CODE]

--
Chandu
Go to Top of Page

atuljadhavnetafim
Starting Member

25 Posts

Posted - 2014-09-29 : 04:57:39
thanks for reply
but i don't want to create new table
i have already extra column and i just want to merge two column in that column

Atul Jadhav
Go to Top of Page

atuljadhavnetafim
Starting Member

25 Posts

Posted - 2014-09-29 : 05:47:47
this code not working
i modify code as below

CREATE TRIGGER Trg_View_1
ON View_1
FOR INSERT, UPDATE
AS
UPDATE View_1 SET payerCustomer = payer + ISNULL (Customer, Payer)
GO


Atul Jadhav
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2014-09-29 : 06:23:55
Why do you want to use UPDATE on view?
You can simply change view definition to include new column.

create view view_1
as
Select column_a, column_b, column_a+ISNULL(column_b, column_a) as column_c
from sometable


Harsh Athalye
http://in.linkedin.com/in/harshathalye/
Go to Top of Page

atuljadhavnetafim
Starting Member

25 Posts

Posted - 2014-09-29 : 07:11:35
becasue my view table is summary of all 6 tables and that view table linked in my local Excel sheet, if it is possible in original table than it is ok for me
but it update whenever i uploade new data in that table

Atul Jadhav
Go to Top of Page
   

- Advertisement -