Dynamic Table Names
Hi there,
Our java develop team plans to change the applications sql code in order to have some queries using table names built dynamicly.
I'd like to know if there will be any impact on performance for actual code changed.
For instante the query:
SELECT a, b from t1
will change to something like:
SELECT a, b from :var_t
where :var_t is a bind variable that can have the value t1.
(The idea is to have a way to user actual code to access actual and historic data in separate tables)
Any help or comments will be very much appreciated.
Helena
You cannot have bind variables in place of table names, column names, and the like, so that's going to be the first problem.
Can you store the data in separate/ multiple partitions of a partitioned table?
Can you create a view over the actual and historical table and specify criteria in your query that allows Oracle to hit the appropriate table?
Justin
Similar Messages
-
How to set dynamic table name in sql query?
I want set dynamic table name by parameter in sql query,just like:
select * from :tbname
but run report is error,BI P report table name is invalidation.
What can i do? Thanks!Hi,
that's only possible inside a data template with a lexical parameter.
Regards
Rainer -
Problem with Dynamic Table Name
Hello all,
I am having trouble using a dynamic table name. I have the following code.....
declare l_cur sys_refcursor;
l_ID int;
l_tableName varchar(30);
BEGIN
open l_cur for
select hkc.ColumnID, mapping from &HKAPPDB_Schema_Name..doctablemapping ddm
inner join &HKDB_Schema_Name..HKColumns hkc on hkc.doctablemappingid = ddm.id
where ddm.id > 0;
LOOP
FETCH l_cur into l_ID, l_tableName;
EXIT WHEN l_cur%notfound;
-- update missing VerbID in DocumentDocMapping table
UPDATE &HKAPPDB_Schema_Name..IndexedDocument
SET VerbID = (SELECT t.VerbID
FROM (SELECT DocRef, VerbID, DateUpdated
FROM &HKAPPDB_Schema_Name..l_tableName dd - this is where the dynamic table name is used
WHERE dd.VerbID is not NULL))
WHERE HKColumnID = l_ID AND VerbID is NULL;
END loop;
end;
/When I try to execute this i get an error
ORA-00942: table or view does not exist
What am I doing wrong?
Regards,
Tobyredeye wrote:
I only started about 6 weeks ago, with no tutorials and learning it on the fly; Same here.. only my introduction was to a 12 node Oracle OPS cluster all those years ago.. and required a whole new mind set after using SQL-Server extensively. But it was fun. Still is. :-)
but thats what you get when a company throws you in at the deep end with a ridiculous time constraint to migrate a whole MSSQL DB.Migrating SQL-Server to Oracle is not a simple thing. A lot of best practices in SQL-Server are absolutely worse practices in Oracle - they are that different. Simple example is lock escalation - an issue in SQL-Server. In Oracle, the concept of a lock being escalated into a page lock simply does not exist.
In terms of getting the migration done as quickly and painlessly as possible I try to reuse all the logic as it appears in the MSSQL code - in this case it was using dynamic table names. I do not doubt that i am probably shooting myself in the foot in the long run.....As long as you do not splatter too much blood on us here.. not a problem :D
Seriously though - just keep in mind that what works in SQL-Server may not work as well (or even at all) in Oracle. So do not hesitate to refactor (from design to code to SQL) mercilessly when you think it is warranted. -
Dynamic table name in an inner join - select statement
Hi,
Please can you let me know if is possible to use a Dynamic table name in an inner join?
Something like the statement below? (It works in a simple select statement but not in an inner join)
SELECT *
INTO CORRESPONDING FIELDS OF <t_itab>
FROM <Dynamic table name> INNER JOIN pa0050 ON
( <Dynamic table name>pernr = pa0050pernr )
WHERE <Dynamic table name>~pernr = it_pernr-l_pernr
AND pa0050~bdegr = f_bdegr.
Any help would be apprecited very much.
Thanks & Regards.Hi,
Check this link.
[http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb39c4358411d1829f0000e829fbfe/frameset.htm]
[Re: accessing dynamic internal table's fields??;
hope it'll help u.
Regards,
Sneha.
Edited by: sneha kumari on Jun 18, 2009 1:57 PM -
Dynamic table name in native SQL
Hi,
How can i use dynamic table name in native SQL?
My req is to select data from a external database table , but the table name will be only poulated during runtime.
How can i acheive this?
Regards,
Arun.It should work OK - see demo below.
Jonathan
report zsdn_jc_adbc_test.
start-of-selection.
perform demo_lookup.
form demo_lookup.
data:
l_error_msg type string,
ls_t001 type t001, "Company
ls_t003 type t003. "Doc types
perform dynamic_lookup
using
'T001'
changing
ls_t001
l_error_msg.
write: / l_error_msg.
perform dynamic_lookup
using
'T003'
changing
ls_t003
l_error_msg.
write: / l_error_msg.
endform.
form dynamic_lookup
using
i_tabname type tabname
changing
os_data type any
o_error_msg type string.
* Use ADBC to select data
data:
l_mandt_ref type ref to data,
l_result_ref type ref to data,
l_mandt type symandt,
l_tabname type tabname,
l_sql_statement type string,
lo_cx_root type ref to cx_root,
lo_cx_sql type ref to cx_sql_exception,
lo_connection type ref to cl_sql_connection,
lo_statement type ref to cl_sql_statement,
lo_result_set type ref to cl_sql_result_set.
clear: os_data, o_error_msg.
get reference of l_mandt into l_mandt_ref.
get reference of os_data into l_result_ref.
l_mandt = '222'. "i.e. select from client 222
l_tabname = i_tabname.
try.
lo_connection = cl_sql_connection=>get_connection( ).
lo_statement = lo_connection->create_statement( ).
* Set criteria for select:
lo_statement->set_param( l_mandt_ref ).
concatenate
'select * from' l_tabname
'where mandt = ?'
into l_sql_statement separated by space.
* Execute
call method lo_statement->execute_query
exporting
statement = l_sql_statement
hold_cursor = space
receiving
result_set = lo_result_set.
* Get the data from the resultset.
lo_result_set->set_param_struct( l_result_ref ).
while lo_result_set->next( ) > 0.
write: / os_data.
endwhile.
* Tidy up:
lo_result_set->close( ).
lo_connection->close( ).
catch cx_sql_exception into lo_cx_sql.
o_error_msg = lo_cx_sql->get_text( ).
catch cx_root into lo_cx_root.
o_error_msg = lo_cx_root->get_text( ).
endtry.
endform. -
Dynamic table name in native sql query
Can i pass a dynamic table name in this query ---
EXEC SQL PERFORMING APPEND_MTO.
SELECT
LTOG_QUANTITY_TYPE,
FCONO,
WBSELEMENT,
PROJECT
INTO :IMTO
FROM RWORKS.MTO_ISO_V2
WHERE LTOD_DATE > TO_DATE(:MAXD,'YYYYMMDDHH24MISS')
ENDEXEC.
How can i pass this table name RWORKS.MTO_ISO_V2 dynamically in the query
Edited by: Madhukar Shetty on Nov 26, 2009 2:40 PMCan i pass a dynamic table name in this query ---
EXEC SQL PERFORMING APPEND_MTO.
SELECT
LTOG_QUANTITY_TYPE,
FCONO,
WBSELEMENT,
PROJECT
INTO :IMTO
FROM RWORKS.MTO_ISO_V2
WHERE LTOD_DATE > TO_DATE(:MAXD,'YYYYMMDDHH24MISS')
ENDEXEC.
How can i pass this table name RWORKS.MTO_ISO_V2 dynamically in the query
Edited by: Madhukar Shetty on Nov 26, 2009 2:40 PM -
Dynamic Table name in Inner Join in 4.6c
data: tab1(10) type c value 'MARA',
tab2(10) type c value 'MAKT'.
data: dbtab1(10) type c,
dbtab2(10) type c .
dbtab1 = tab1.
dbtab2 = tab2.
DATA: BEGIN OF itab occurs 0,
matnr TYPE mara-matnr,
maktx type makt-maktx,
END OF itab.
DATA: column_syntax TYPE string,
dbtab_syntax TYPE string.
PARAMETERS: p_matnr TYPE mara-matnr.
dbtab_syntax = '( (dbtab1) AS t1 '
&' INNER JOIN (dbtab2) AS t4 ON t1MATNR = t4MATNR )'.
SELECT matnr maktx
FROM (dbtab_syntax)
INTO TABLE itab WHERE t4~matnr = p_matnr.
Got the following error:
"A table name, specified in an SQL command, is unknown"
It seems not able to read dynamic table name in dbtab_syntax.
thanks
anya
Moderation Message: Duplicate Post.
Edited by: kishan P on Nov 29, 2010 11:17 AMHi,
Check this link.
[http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb39c4358411d1829f0000e829fbfe/frameset.htm]
[Re: accessing dynamic internal table's fields??;
hope it'll help u.
Regards,
Sneha.
Edited by: sneha kumari on Jun 18, 2009 1:57 PM -
Passing dynamic table name in ADO. net destination
I am new to SSIS and I have a requirement where i need to pass dynamic table name in ADO .net destination .
My package contains an "Execute Sql task" in the control flow which computes the destination table name to be provided at run time and stores it in a variable expression
"@[User::Table_name]"(which has a scope of full package).
Now, the problem I'm facing right now is that , I am unable to use this variable expression in the ADO .Net Destination .
I need to pass this variable expression as the table name in ado .net destination.
But, whenever I use this variable in place as the table name I keep on getting this error and my package fails:-
[ADO NET Destination [403]] Error: The Table or View name is not expected. \n\t If you are quoting the table name, please use the prefix " and the suffix " of your selected data provider for quotation. \n\t If you are using multipart name,
please use at most three parts for the table name.
Although ,I am able to run my package when i am providing the existing(static) table name.So there is nothing wrong with the package.
Tried a lot of things still not working..Please help...I am having the result stored in the variable expression . I just need a way to be able to use it as the Destination table in ADO .net Destination.
I am not sure if this will work for you, but I am able to store the table name in variable and use it dynamically (via data flow task expression property ) as shown.
Thanks, hsbal
Hi Adeep,
Based on my further research, just as hsbal said, we can set a variable as ADO.NET Destination table via Expressions property in Data Flow Task.
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
After run (or test) of procedure
create or replace procedure tmp_select_dymanic
( AInTable IN VARCHAR2,
ACount OUT NUMBER
) as
begin
EXECUTE IMMEDIATE 'BEGIN SELECT count(*) INTO :Count FROM :InTable END;'
USING ACount, AInTable;
end tmp_select_dymanic;
error message: invalid table name.
I know the table exists and contains data. I can make SELECT in SQL (not dynamic).
What a reason for error? May be privileges in database? But i make SELECT on my own table?
How can i set dynamic table name in other way?
My Oracle Version 10g.What you are asking can be done by REF_CURSOR;
look this example and try your self the rest:
CREATE OR REPLACE PROCEDURE insert_to_table_dinamic (
table1 IN VARCHAR2,
table2 IN VARCHAR2
AS
rc sys_refcursor;
v_sql VARCHAR2 (2000);
v_deptno NUMBER;
BEGIN
v_sql :=
'SELECT DEPTNO FROM '
|| table1
|| ' WHERE ROWNUM = 1 AND DEPTNO IS NOT NULL';
OPEN rc FOR v_sql;
LOOP
FETCH rc
INTO v_deptno;
EXIT WHEN rc%NOTFOUND;
v_sql :=
'UPDATE '
|| table2
|| ' SET DEPTNO = '
|| v_deptno
|| ' WHERE DEPTNO IS NULL';
EXECUTE IMMEDIATE v_sql;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (SQLCODE || SQLERRM);
END insert_to_table_dinamic;when i give DEPT , EMP as my 2 parameters above code will set the deptno in EMP table where deptno is null;
--Just a test proc. -
Dynamic table name from Arguments in cfquery /
I'm trying to use dynamic table names in a cfc but seem to
have hit upon a wall as my calling methods from flash keep hitting
my _error methods - Code attached to show what I'm trying to
achieve; if anyone can give me some pointers it would be a great
help. I've seen numerous by using the Form with the arguments but
this is coming into a gateway used by a flash component and doesn't
work no matter how much I fiddle the code.
Thanks in advanceThere was a time when I needed a dynamic query such as this.
BUT, it is very dangerous, which is why I took a few steps to make
it more secure.
1. Always use cfqueryparam and strict datatyping
2. Use listFindNoCase for known table names in the database
e.g
<cfset variables.tableNames =
"items,products,categories,blog" />
<cfif
listContainsNoCase(variables.tableNames,lCase(trim(arguments.tableName)),",")>
query here
<cfelse>
Error: Unknown table requested
</cfif>
Mikey -
(Urgent) Dynamic Table Name
Hi Fellows,
Can I use dynamic table name in a loop? I have a problem that I want to use variable table in a cursor for example
procedure check_rows as
cursor c1 is
select view_name
from user_views;
v_count number;
v_view_name varchar2(35);
begin
for i in c1 loop
select count(*)
into v_count
from i.view_name;
if v_count = 0 THEN
dbms_output.put_line ('The View '| |i.view_name| |' has no rows');
end if;
end loop;
end;
but i receive a message
i.view_name must a name of a table to which the user has access.
Can anybody solve my problem.
Thanks in advance
MustafaHere is some codes I wrote with DBMS_SQL. I hope it will help you to start.
PROCEDURE Get_record(p_select IN OUT select_rec, where_str IN OUT varchar2) IS
my_keyblk varchar2(6);
veh_id integer;
ser_date date;
succ_flag number;
blk_route varchar2(4);
blk_run integer;
my_date_type integer;
cur_blk_route INTEGER;
rows_processed INTEGER;
ignore integer;
select_str varchar2(3000);
First_date date;
Last_date date;
BEGIN
begin
select start_date, end_date into first_date, Last_date from change_date
where current_next_code = 'CURRENT';
exception when others then
null;
end;
select_str := 'select keyblock, keycoach, proflag, pullout_date
from logblock
where (pullout_date between first_date and Last_date)
and proflag = 0';
cur_blk_route := dbms_sql.open_cursor;
dbms_sql.parse(cur_blk_route, select_str, dbms_sql.v7);
dbms_sql.define_column(cur_blk_route, 1, blk_route, 6);
dbms_sql.define_column(cur_blk_route, 2, blk_run);
dbms_sql.define_column(cur_blk_route, 3, veh_id);
dbms_sql.define_column(cur_blk_route, 4, ser_date);
ignore := dbms_sql.execute(cur_blk_route);
LOOP
if (dbms_sql.fetch_rows(cur_blk_route) > 0) then
dbms_sql.column_value(cur_blk_route, 1, blk_route);
dbms_sql.column_value(cur_blk_route, 2, blk_run);
dbms_sql.column_value(cur_blk_route, 3, veh_id);
dbms_sql.column_value(cur_blk_route, 4, ser_date);
else
dbms_output.put_line('ERROR ');
end if;
END LOOP;
dbms_sql.close_cursor(cur_blk_route);
END Get_record;
end apc_block_assign;
null -
Dynamic table name in select statment
hai,
Please help me....
oracle 9i i am using.
i have four tables abc_121,
abc_122,
abc_123,
abc_124.
i want to pick records from a table.table name should be prepared dynamically.
i.e., i want to pick records from a quarter table of this year.(ex: abc_124). using sql statement only.
i have tried..but i couldn't...... pls help me...ramadurga.v wrote:
oracle 9i i am using.
i have four tables abc_121,
abc_122,
abc_123,
abc_124.
i want to pick records from a table.table name should be prepared dynamically.
i.e., i want to pick records from a quarter table of this year.(ex: abc_124). using sql statement only.Create a partition view. E.g.
create or replace view abc as
select * from abc_121
union all
select * from abc_122
union all
...For the partition view approach to correctly work (doing "partition pruning"), you need to have a constraint on the column that identifies that partition.
In other words, you cannot use the table name as an attribute to identifies its data content. Foe example, you can have tables YEAR2001_Q1 and YEAR2001_Q2. However, the year and quarter also need to be in the table itself - e.g. columns YEAR and QUARTER.
For table YEAR2001_Q1, the YEAR column needs to have a check constraint that ensures it is always 2001. And a check constraint for column QUARTER to ensure that it is always 1.
If these conditions are met, then a select from the partition view using +"where YEAR=2001 and QUARTER=2"+ will result in only table YEAR2001_Q2 to be used and not other tables like YEAR2001_Q1.
See {message:id=10539404} for an example. -
Dynamic table name, how to query?
Hi!
There is a table name that is decided dynamically. the name is:
someNameYYY where YYY denotes the client number.
I get the client number by sy-mandt and concatenate it with someNameYYY to lc_table_name but then comes the problem:
I cannot do
SELECT *
FROM lc_table_name
because I get compiler error "lc_table_name" is not defined in ABAP dictionary.
How do I query a table with the name decided dynamically?
regards
BaranYou can have do something like this :
REPORT ZTABLE_DOWNLOAD .
tables :
dd02l, "SAP Tables
dd03l, "Table fields
dd04t. "R/3 DD: Data element texts
constants : c_activation_status(1) value 'A',
c_tabclass(6) type c value 'INTTAB',
c_language(2) type c value 'EN'.
type-pools : slis.
selection-screen begin of block b1 with frame title text-003.
*parameters :p_mandt like t001-mandt obligatory default '560'.
parameters :p_table like dd03l-tabname obligatory.
selection-screen end of block b1.
data:
table_desc(70) type c,
table_field like dd03l-fieldname,
total_rows type i,
t_rows(20) type c.
field-symbols:
<fs_line> type any,
<fs_field> type any.
at selection-screen.
*Check for the existence of the table
select single * from dd02l where tabname = p_table
and as4local = c_activation_status.
if sy-subrc ne 0.
*Table is not active in dictionary
message e999(zs) with 'Table is not active in dictionary'.
elseif dd02l-tabclass = c_tabclass.
*It is a structure not a table
message e999(zs) with 'This is a structure not a table'.
endif.
start-of-selection.
perform table_data_display.
end-of-selection.
form table_data_display.
data:
l_long_type type i,
lx_struct type ref to data,
lt_table type ref to data,
lcl_sdescr type ref to cl_abap_structdescr,
lx_lvc_cat type lvc_s_fcat,
lt_lvc_cat type lvc_t_fcat, "Field catalog
lx_fieldcat type slis_fieldcat_alv,
lt_fieldcat type slis_t_fieldcat_alv,
lx_layout type slis_layout_alv,
lt_sort type slis_t_sortinfo_alv, "Sort table
ls_sort type slis_sortinfo_alv.
field-symbols :
<fieldcat> type slis_fieldcat_alv,
<lt_table> type table,
<fs> type any,
<components> type abap_compdescr.
*Dynamic creation of a structure
create data lx_struct type (p_table).
assign lx_struct->* to <fs>.
*Get the field structure
lcl_sdescr ?= cl_abap_typedescr=>describe_by_data( <fs> ).
loop at lcl_sdescr->components assigning <components>.
*Do not display field "MANDT"
IF sy-tabix = 1 AND <components>-name = 'MANDT'.
CONTINUE. "next loop
ENDIF.
*Build fieldcatalog
lx_lvc_cat-fieldname = <components>-name.
lx_lvc_cat-ref_table = p_table.
append lx_lvc_cat to lt_lvc_cat.
lx_fieldcat-fieldname = <components>-name.
lx_fieldcat-ref_tabname = p_table.
append lx_fieldcat to lt_fieldcat.
endloop.
*Create an internal table
call method cl_alv_table_create=>create_dynamic_table
exporting it_fieldcatalog = lt_lvc_cat
importing ep_table = lt_table.
assign lt_table->* to <lt_table>.
*Read the data
select * from (p_table)
into corresponding fields of table <lt_table>
order by primary key.
loop at <lt_table> assigning <fs_line>.
assign component 'MANDT' of
structure <fs_line> to <fs_field>.
<fs_field> = p_mandt.
endloop.
if <lt_table>[] is initial.
*No table enties are existing
message e003(zdynamictable) with p_table.
exit.
else.
describe table <lt_table>[] lines total_rows.
t_rows = total_rows.
shift t_rows left deleting leading space.
endif.
*Specify the layout
lx_layout-zebra = 'X'.
lx_layout-colwidth_optimize = 'X'.
*Display the ALV List
select single ddtext into table_desc from dd02t
where tabname eq p_table and ddlanguage eq c_language.
check not table_desc is initial.
concatenate 'Entries from table:'
p_table '(' table_desc ')' '-:' t_rows 'Entries Found' into
table_desc
separated by space.
*Start - Download the data to excel sheet by validating the file path.
data:
*lv_filename type string,
lv_fname_validate like rlgrap-filename.
*CONCATENATE 'C:\ZTABLE_DWN\' P_TABLE '.Xls' INTO LV_FILENAME.
*CONCATENATE '
Pc-p31061\Harman\Tasks\ZTABLE_DWN\' P_TABLE '.xls' INTO
CONCATENATE 'C:\ZTABLE_DWN\' P_TABLE '.xls' INTO
LV_FNAME_VALIDATE.
call function 'WS_FILE_DELETE'
exporting
file = lv_fname_validate
IMPORTING
RETURN =
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
BIN_FILESIZE = ' '
CODEPAGE = ' '
FILENAME = LV_FNAME_VALIDATE
FILETYPE = 'DAT'
IMPORTING
FILELENGTH =
TABLES
DATA_TAB = <lt_table>.
*call function 'GUI_DOWNLOAD'
exporting
BIN_FILESIZE =
filename = lv_fname_validate
filetype = 'ASC'
write_field_separator = 'X'
IMPORTING
FILELENGTH =
tables
data_tab = <lt_table>.
End of Download.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_background_id = 'ALV_BACKGROUND'
i_grid_title = table_desc
is_layout = lx_layout
it_fieldcat = lt_fieldcat
tables
t_outtab = <lt_table>
exceptions
program_error = 1
others = 2
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
clear table_desc.
endform. " table_data_display -
Hello Expert,
I wanted to know is there any way through which we can dynamically pass the table name in IMPORT condition.
For e.g.
DATA : PCLT TYPE DD03L-TABNAME.
DATA: SET_RELID TYPE T52RELID-RELID.
DATA: key TYPE PCLKEY.
DATA: text_version TYPE PVRSN.
DATA: BEGIN OF ptext OCCURS 132.
DATA: line(132).
DATA: END OF ptext.
SET_RELID = 'TX'.
PCLT = 'PCL1'.
KEY = '00001000004005 9999123119960101000'.
TEXT_VERSION = '01'.
IMPORT TEXT_VERSION PTEXT FROM DATABASE <PCLT>(<SET_RELID>) ID KEY.
If i use this then it gives me error message "The Dictionary structure or table "<PCLT>" is either not active or does not exist."
Kindly help me in this matter.
Thanks
SrikanthHi Srikanth
I dont know if there is another solution, but this is what i did using a dynamic subroutine, please check it
just add this lines to your code
DATA: prog TYPE c LENGTH 8,
mess TYPE string,
sid TYPE string,
wrd TYPE string,
dir TYPE trdir,
OFF(3).
DATA: lt_code TYPE TABLE OF rssource-line.
DATA: ls_code TYPE rssource-line.
perform call_import using pclt set_relid key.
form call_import USING p_pclt p_set_relid p_key.
ls_code = 'PROGRAM SUBPOOL.'.
append ls_code to lt_code.
ls_code = 'form get_text tables ptext using p_key changing text_version.'.
append ls_code to lt_code.
ls_code = 'IMPORT text_version ptext from database'.
append ls_code to lt_code.
concatenate p_pclt '(' p_set_relid ')' into ls_code.
append ls_code to lt_code.
ls_code = 'id p_key.'.
append ls_code to lt_code.
ls_code = 'endform.'.
append ls_code to lt_code.
generate subroutine pool lt_code
name prog
message mess
SHORTDUMP-ID sid
WORD WRD
OFFSET OFF.
IF SY-SUBRC EQ 0.
perform GET_TEXT IN PROGRAM (prog) tables ptext
USING p_key
CHANGING text_version .
ENDIF.
endform.
Hope this help
Regards
MC -
In my control flow, I set up a variable for the table name, enumerated by SMO, following the instructions from the link here:
http://www.bidn.com/blogs/mikedavis/ssis/156/using-a-for-each-loop-on-tables-ssis
Now, I put a data flow task inside the foreach. I selected the OLE DB connection manger for my database, set the Data access mode to "Table name or view name variable", and selected my variable name from the drop down. So far so good. When I click on OK,
it gives me an error 0x80040E37, basically saying it can't open the rowset for "my variable", Check that the object exists in the database.
So, I assume I won't be able to do this "that' easily, and I will need to build a "SQL command from variable" or some such thing. Any advice on how to build this Source editor to dynamically name my columns from the variable?
Thanks in advance!
mpleafHi mpleaf,
Please try to set "ValidateExternalData" to False in your OLE DB Source Properties and "DelayValidation" property to TRUE, please refer to similar threads:
http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/thread/620557d9-41bc-4a40-86d5-0a8d2f910d8c/
http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/thread/456f2201-447c-41b3-bf27-b3ba47e6b737
Thanks,
Eileen
Eileen Zhao
TechNet Community Support -
Create table with dynamic table name.
I'm trying to create a table
like
select x.*, convert(nvarchar(20), getdate(), 101) AS LoadDate
into table1_20140512
from (
select c1,c2,c3 from table2_20140512
WHERE(LoadDate = (select MAX(LoadDate) FROM table2_20140512 )
union all
select c1,c2,c3 from table3_20140512
WHERE(LoadDate = (select MAX(LoadDate) FROM table3_20140512 )
) X
I want to make table name dynamic, like 'table1'+toady's date
I declared three variables, but they didn't work as I expected
These are my variables
DECLARE @table1 nvarchar(500)
DECLARE @table2 nvarchar(500)
DECLARE @table3 nvarchar(500)
SET @table1='H1_' +(CONVERT(VARCHAR(8),GETDATE(),112))
SET @table2='H2_' +(CONVERT(VARCHAR(8),GETDATE(),112))
SET @table2='H3_' +(CONVERT(VARCHAR(8),GETDATE(),112))Try the following:
DECLARE @SQL nvarchar(2000);
DECLARE @table1 nvarchar(500) ='H1_' +(CONVERT(VARCHAR(8),GETDATE(),112));
DECLARE @table2 nvarchar(500) ='H2_' +(CONVERT(VARCHAR(8),GETDATE(),112));
DECLARE @table3 nvarchar(500) ='H3_' +(CONVERT(VARCHAR(8),GETDATE(),112));
PRINT @table1+' '+@table2+' '+@table3;
--H1_20140512 H2_20140512 H3_20140512
SET @SQL = 'select x.*, convert(nvarchar(20), getdate(), 101) AS LoadDate
into '+QUOTENAME(@table1)+'
from (
select c1,c2,c3 from table2_20140512
WHERE(LoadDate = (select MAX(LoadDate) FROM '+QUOTENAME(@table2)+' ))
union all
select c1,c2,c3 from table3_20140512
WHERE(LoadDate = (select MAX(LoadDate) FROM '+QUOTENAME(@table3)+' ))
) X '
PRINT @SQL; -- debugging
/* select x.*, convert(nvarchar(20), getdate(), 101) AS LoadDate
into [H1_20140512]
from (
select c1,c2,c3 from table2_20140512
WHERE(LoadDate = (select MAX(LoadDate) FROM [H2_20140512] ))
union all
select c1,c2,c3 from table3_20140512
WHERE(LoadDate = (select MAX(LoadDate) FROM [H3_20140512] ))
) X
EXEC sp_executeSQL @SQL;
Dynamic SQL examples:
http://www.sqlusa.com/bestpractices/dynamicsql/
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012
Maybe you are looking for
-
Problem with file association in Photoshop
I am using Adobe Photoshop CS4, and I also have Adobe After Effects on my computer (which I don't use). For some reason, when I click on a photograph in Adobe Bridge, the After Effects program opens, but the photo I want to open in Photoshop does no
-
I've downloaded the Creative Cloud app but the App tab says there is a download error and to contact support. I have tried uninstalling and reinstalling and am gettting the same message. I'm running OS X 10.9.3.
-
Exchange 2013 recipient filter working bad
Hello, I have seen, that the recipient filter in Exchange 2013 is working a Little bit different like in the older Versions. Here an Example (Exchange 2013): <<<220 EX2013.test.local Microsoft ESMTP MAIL Service ready at ..... >>>helo test <<<250 EX2
-
Hello all out there I am in desperate need of some help.I just recently bought an iphone here.When I downloaded Itunes for the first time it was a while ago and then at that time as i was not really using it, I deleted manually the file named "Apple
-
Windows 8, set default application for example adobe reader, customize the start screen
I have two questions, Im going to deploy Windows 8 to our company, but have 2 big issues. 1) I need to customize the start screen, but cant find anywhere in the gpo´s? How can I do this without sysprepping etc (deploying with SCCM2012 SP1) 2) I need