Hi,
I am trying to insert the Source name and clientId to a table called clientSource...
The User will send in some Dbf File... So in a particular file called PlanDbf.. I have the following fields
PlanNumber, Name, SRC1Name, SRC2Name, SRC3Name... SRC20Name
170234 Constructions Employee Deferral Employer Discretionary Employer Matching...
And in another table called SourceDBF i have the following fields with data
PlanNumber PARTID SOURCE_NUM etc...
170234 123456789 1
170234 123456789 3
170234 451231334 1
So how do i match the Source_NUM with SRCnames when i insert it into the table..
INSERT INTO Statement..ClientSource
(
@.ClientId,
SourceName
)
SELECT
s.SOURCE_NUM
FROM SourceDBF ..
but i am stuck..
any help will be appreciated.
Regards
Karen
I cant see a connection between them. How are they related?
|||
The 2 tables are related by the plan number...
and will know by taking a look at the PlanDBF if its 1 then to pull ... SRC1Name...
|||Sorry I still cant get it.. can you just post few rows from each tables and expected output so its easier to understand (at least for me)..
|||this is how the table that i need to insert is ...
SourceId (int identity) ClientID SourceName
And i will be getting the Data the source name from the Table...
PlanDBF (which has one row of data)
PlanNumber, Name, SRC1Name, SRC2Name, SRC3Name... SRC20Name
170234 Constructions Employee Deferral Employer Discretionary Employer Matching...
and then once i insert the data to the above table called source.. I am inserting the data from the Source Summary which is as follows
PlanNumber PartId Source_NUM begbal dep withdrawels etc..
to another table ParticipantSourceSummary which has the has the follow fields
Plan Number PartId SourceId (which will be got from the clientSource table) and the remaining fields from the SourceSummary table
So at the end while i generate a report i want Source_NUm 1 to be whats in SRCName and so on
Hope this is clear.
Regards
Karen
|||CREATE VIEW vw_Sources AS
SELECT PlanNumber,Src1Name AS SourceName,1 AS Source_Num
FROM PlanDBF
UNION ALL
SELECT PlanNumber,Src2Name AS SourceName,2 AS Source_Num
FROM PlanDBF
UNION ALL
SELECT PlanNumber,Src3Name AS SourceName,3 AS Source_Num
FROM PlanDBF
{repeat 17 more times}
--
Not sure of all your relations, but then you can do something like this:
SELECT s.PlanNumber,s.PartID,s.Source_Num,vw_Sources.SourceName
FROM SourceDBF s
JOIN vw_Sources ON s.PlanNumber=vw_Sources.PlanNumber AND s.SOURCE_NUM=vw_Sources.SOURCE_NUM
|||Alternatively, you can do this:
SELECT s.PlanNUmber,s.PartID,s.Source_Num,
(SELECT CASE s.Source_Num WHEN 1 THEN Src1Name WHEN 2 THEN Src2Name WHEN 3 THEN Src3Name ... END FROM PlanDBF p WHERE p.PlanNumber=s.PlanNumber) AS SourceName
FROM SourceDBF
|||Motley,
Thanks a lot.. the solution works for me
Regards,
Karen
No comments:
Post a Comment