[英]How do I select a field from a table where I am looking up the fieldname from another table?
Doing some ETL and I have a wide file with lots of cols, for each different value. 做一些ETL,我有一个包含大量cols的宽文件,每个不同的值。 I am trying to transform this into a vertical text file with one row per value item.
我试图将其转换为垂直文本文件,每个值项有一行。 So my data table looks like;
所以我的数据表看起来像;
Store Date Col1 Col2 Col3 ...
Store1 1/2/12 12 23 34 ...
Store2 1/2/12 23 34 35 ...
My Col lookup table looks like; 我的Col查找表看起来像;
GLCode GLDesc TaxRate XLSColName
00.1234 Cash 0.00 Col2
So in my output file line I need; 所以在我的输出文件行中我需要;
Store1,1/2/34,00.1234,0.00,23
where 23 is the value from the Data table in the Col2 field which was specificed in teh GL Lookup field. 其中23是Col2字段中Data表中的值,该字段在GL Lookup字段中指定。
I have been trying to do this is SQL as part of an SSIS package, as I could not see how to do it with the Lookup task, but cannot seem to do it in SQL either !! 我一直在尝试这样做是SQL作为SSIS包的一部分,因为我无法看到如何使用Lookup任务执行它,但似乎无法在SQL中执行它!
Hope that makes sense and thanks for your help ! 希望有意义并感谢您的帮助! JK
JK
From your what I understand of your question, you're looking for the SQL Server UNPIVOT function , which takes columns and pivots them into individual rows/values. 根据我对您的问题的理解,您正在寻找SQL Server UNPIVOT函数 ,该函数接受列并将它们转换为单独的行/值。 Combine that with a join to get your required information from the Lookup table.
将其与联接组合以从查找表中获取所需信息。
To do this in SSIS, you could use the UNPIVOT Transformation 要在SSIS中执行此操作,可以使用UNPIVOT Transformation
You will need to look at pivoting the data table from: 您将需要查看从以下位置转动数据表:
Store Date Col1 Col2 Col3 ...
Store1 1/2/12 12 23 34 ...
Store2 1/2/12 23 34 35 ...
Store Date Col Value
Store1 1/2/12 Col1 12
Store1 1/2/12 Col2 23
Store1 1/2/12 Col3 34
Store2 1/2/12 Col1 23
Store2 1/2/12 Col2 34
Store2 1/2/12 Col3 35
So you can treat the column name as data to be joined/looked up. 因此,您可以将列名称视为要加入/查找的数据。
Your question is a little confusing. 你的问题有点令人困惑。 I understand what you are trying to do but not 100% sure where the data is stored.
我明白你要做什么,但不能100%确定数据的存储位置。 Is this correct?: You have 2 tables, 1 table has the data you want?
这是正确的吗?:你有2个表,1个表有你想要的数据吗? 1 table has the value to search the first table for?
1表有搜索第一个表的值吗?
If so you want something like: 如果是这样你想要的东西:
SELECT t1.col1, t1.col2, ...
FROM table_1 t1
LEFT JOIN table_2 t2 ON t1.common_field = t2.common_field
WHERE t2.search_by = 'CRITERIA'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.