SQL Query

atuljadhavnetafim

Active Member
Joined
Apr 7, 2012
Messages
341
Office Version
  1. 365
Platform
  1. Windows
Dear Expert

i have 6 table in SQL Server and i have created one View ("View_1") and in that i have one column name ("PayerCustomer")
i want value in this column which merge two column like Column name "Payer" and second column "Customer"

e.g in Payer column have Value "Atul"
and in Customer Column have value "Jadhav"
then i want to merge this two value and want result in "PayerCustomer" like "AtulJadhav"
and if Second Column is blank then it give me value like "AtulAtul"

so i have tied below code but it is not wokring


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

please help
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
That's not got anything to do with triggers and you insert into Tables, not Views.

I think you're confused, are you just wanting to concatenate the Payer and Customer fields in your view? If so all you need is:
Code:
SELECT
    payer + ISNULL(Customer, payer) [PayerCustomer]
FROM
    MYTable

You don't update Views, they don't hold data, they are what they say on the tin "Views" of your data, so they just display the data in your tables
 
Upvote 0
There's no code to run. You don't update views. They run the code every time you query them
 
Upvote 0
actualy i had read some where, this can be happed with the help of trigeer
and i tried your code but it give me only one column and i don't want that

either my original table shoud update that column or my view table column update automatic

can this possible in SQL ?
 
Upvote 0
You're doing it wrong. This has nothing to do with Triggers, you don't update Views and you don't store presentation logic in your Table. If you want all the columns in the view then try:
Code:
SELECT
    *, payer + ISNULL(Customer, payer) [PayerCustomer]
FROM
    MYTable
 
Upvote 0
this my original code for view the 6 table in one single table, where PayerCustomer value is "Null" i want merge field in this column


SELECT dbo.Revenue_Master.Profit_Center, dbo.Revenue_Master.Month_Year, dbo.Revenue_Master.Payer, dbo.Revenue_Master.Customer, dbo.Revenue_Master.Material,
dbo.Revenue_Master.Product_Group, dbo.Revenue_Master.Product, dbo.Revenue_Master.Billing_document, dbo.Revenue_Master.Sales_Val, dbo.Revenue_Master.Net_Revenue,
dbo.Revenue_Master.Discounts, dbo.Revenue_Master.Transportation_Revenue, dbo.Revenue_Master.Sales_Commision, dbo.Revenue_Master.Sales_Qty, dbo.Revenue_Master.Sales_Qty1,
dbo.Revenue_Master.Material_Cons_Val, dbo.Customer_Master_Test.Name, dbo.Customer_Master_Test.Rg, dbo.Product_Group.Description, dbo.Product_Group.Product_Group AS Expr1,
dbo.Revenue_Master.PayerCustomer
FROM dbo.Revenue_Master INNER JOIN
dbo.Customer_Master_Test ON dbo.Revenue_Master.Payer = dbo.Customer_Master_Test.Customer INNER JOIN
dbo.Product_Group ON dbo.Revenue_Master.Product = dbo.Product_Group.Product
 
Upvote 0
You're getting a bit mixed up still :( what that gives you is a recordset not a table. However I think you want:

SELECT dbo.revenue_master.profit_center,
dbo.revenue_master.month_year,
dbo.revenue_master.payer,
dbo.revenue_master.payer
+ Isnull(dbo.revenue_master.customer, dbo.revenue_master.payer)
[PayerCustomer],
dbo.revenue_master.customer,
dbo.revenue_master.material,
dbo.revenue_master.product_group,
dbo.revenue_master.product,
dbo.revenue_master.billing_document,
dbo.revenue_master.sales_val,
dbo.revenue_master.net_revenue,
dbo.revenue_master.discounts,
dbo.revenue_master.transportation_revenue,
dbo.revenue_master.sales_commision,
dbo.revenue_master.sales_qty,
dbo.revenue_master.sales_qty1,
dbo.revenue_master.material_cons_val,
dbo.customer_master_test.NAME,
dbo.customer_master_test.rg,
dbo.product_group.description,
dbo.product_group.product_group AS Expr1,
dbo.revenue_master.payercustomer
FROM dbo.revenue_master
INNER JOIN dbo.customer_master_test
ON dbo.revenue_master.payer = dbo.customer_master_test.customer
INNER JOIN dbo.product_group
ON dbo.revenue_master.product = dbo.product_group.product
 
Upvote 0

Forum statistics

Threads
1,214,869
Messages
6,122,012
Members
449,060
Latest member
LinusJE

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top