Stacie
asked on
Create a sql function that Add two value from two joint table and place it in the master table
I have the following table: and I would like to write a function that take the value LocId Int Foreign key to LocTable and
DeptId Int Foreign key to DeptTable and add these two value such as A + ' ' + B and insert this value in a new column table.
Client Table
ClientID Int
Name NVARCHAR(100)
LastName NVARCHAR(100
LocId Int Foreign key to LocTable
DeptId Int Foreign key to DeptTable
LocId This should be a value from the following table
DeptTable
Id
Name
LocTable
Id
Name
DeptId Int Foreign key to DeptTable and add these two value such as A + ' ' + B and insert this value in a new column table.
([dbo].[AddTwoValuesPhone]([Location],[Department]))
USE [ztools]
GO
/****** Object: UserDefinedFunction [dbo].[AddTwoValuesPhone] Script Date: 10/29/2014 16:39:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <GUYON, Yves>
-- Create date: <200141027, ,>
-- Description: <Phone Book, ,>
-- =============================================
ALTER FUNCTION [dbo].[AddTwoValuesPhone](@Location NVARCHAR(100),@Department NVARCHAR(150))
RETURNS NVARCHAR(150)
AS
BEGIN
DECLARE @Result NVARCHAR(150)
SET @Result = @Location + ' - ' + @Department
RETURN
(
@Result
)
END
Client Table
ClientID Int
Name NVARCHAR(100)
LastName NVARCHAR(100
LocId Int Foreign key to LocTable
DeptId Int Foreign key to DeptTable
LocId This should be a value from the following table
DeptTable
Id
Name
LocTable
Id
Name
What is a "new column table" and why is a view not sufficient?
ASKER
Never done a view... No I just want the data to be placed back in a column in the client Table
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you and how do I call this view to get populated from my table column?
Use BOL: CREATE VIEW (Transact-SQL)
So it's a simple
Creates a virtual table whose contents [..]
So it's a simple
SELECT *
FROM myFirstView ;
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for yguyon28's comment #a40413052
Assisted answer: 250 points for ste5an's comment #a40412060
Assisted answer: 250 points for ste5an's comment #a40413156
for the following reason:
It work
Accepted answer: 0 points for yguyon28's comment #a40413052
Assisted answer: 250 points for ste5an's comment #a40412060
Assisted answer: 250 points for ste5an's comment #a40413156
for the following reason:
It work
So you used a view or something else?