Create a Union query that automatically adds/contains new tables with a similar name

Dear All, 
For a research project i am upscaling from an Access database to SQL server/ SQL azure since the database got far too large. Now i am quite well known with Access, but to be quite honest, I am a SQL rookey. So a lot to learn for me here. 
what I need is a union query that automatically adds new research dumps to the query. All research dumps have a table name starting with TD_EXP (Table Dump _ Export). In Access VBA I simply made a loop that builds up the SQL statement, but i have no clue
how to do this within SQL Server...
So, I need the UNION Query to select * from TD_Exp_2012_06_06_15_48 UNON all the  TD_Exp_XXXX_XX_XX_XX_XX that are added in the database,
Who could help me out please with a dynamic SQL statement. 
Best regards  Jurjen

you can use INFORMATION_SCHEMA.TABLES view for that
do like below
DECLARE @Query varchar(max)
SELECT @Query = STUFF((SELECT ' UNION ALL ' + 'SELECT * FROM ' + TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'TD_EXP%' FOR XML PATH('')),1,11,'')
SELECT @Query
Add one more condition as below if you want to exclude views from above 
DECLARE @Query varchar(max)
SELECT @Query = STUFF((SELECT ' UNION ALL ' + 'SELECT * FROM ' + TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'TD_EXP%' AND TABLE_TYPE = 'BASE TABLE' FOR XML PATH('')),1,11,'')
SELECT @Query
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Similar Messages

  • Trying to automatically add a new row w/o mutating table error...

    I'm using Oracle 10g express. I'm trying to automatically add a new row with the same e_ID, (RDD + 6 months) as the updated row when RC is updated. I'm fairly new to Oracle, so I need some help on creating a trigger. If you need more details let me know. Thanks in advance.
    create table E
    e_id number(6,0) not null,
    constraint e_pk primary key(e_id)
    create Table ER
    e_Id Number(6,0) Not Null,
    SC Date,
    RDD Date,
    RC Date,
    Constraint ER_Fk Foreign Key(E_Id) References E(E_Id)
    );

    mookjais wrote:
    I'm using Oracle 10g express. I'm trying to automatically add a new row with the same e_ID, (RDD + 6 months) as the updated row when RC is updated. I'm fairly new to Oracle, so I need some help on creating a trigger. If you need more details let me know. Thanks in advance.
    create table E
    e_id number(6,0) not null,
    constraint e_pk primary key(e_id)
    create Table ER
    e_Id Number(6,0) Not Null,
    SC Date,
    RDD Date,
    RC Date,
    Constraint ER_Fk Foreign Key(E_Id) References E(E_Id)
    );Do you mean following(example)?
    create trigger after_insert_e
    after
      insert
    on  e /*This is table name*/
    referencing new as new old as old
    for each row
    begin
    insert into  ER(e_Id,SC,rdd,rc)
    values(:new.ed_id,sysdate,sysdate,sysdate);
    end;

  • Need to add a new View With ITS Link in it

    Hello All ,
      I am Working on SAP CRM 7.0 in Marketing here in marketing We do have an Account Work Center here in account we have three views Search , Create and Report .I want to add a new view with name "XYZ" in this view i want have Logical links . This logical link is ITS (Transaction Launcher ). Can any one Tell me the Procedure for this . Thanks in Advance
    regards,
    KiranPosanapalli

    Solved by myself

  • Yosemite automatically adds a new desktop everytime i start my mac; pls help

    Yosemite automatically adds a new desktop everytime i start my mac; pls help
    i have upgraded my mac pro to Yosemite few days earlier and i find an annoying problem whenever i start my mac it automatically adds a new desktop...and when i open my mission control it shows me number of desktops which i haven't added myself; one more thing i am using 2 displays for my system; pls help

    If I open up the AirPort App - it only says that it cannot find my AirPort wireless device (probably because I dont have one) and then if I go to networks to connect to my wifi I select my home network and it ask me to input a password (as it should) but when I try to put in my password for my network it says "connection timeout" and the screen behind it (where the options for wifi or ethernet ext are) it says no ip address under wifi (also the status indicator is showing yellow - since my wifi is on just not connected to a network. I cannot seem to find any place to input my information for my specific router. Although I can connect to neighboring wifi routers just fine.

  • I need to create 4 A2 boards that print adjacent to one another with a photo image running across all 4 boards.How do I set up the pages so I can see the whole composition together , then print the seperate A2 boards.Do I use illustrator (C3) or Indesign?

    I need to create 4 @ A2 boards that print adjacent to one another (all landscape format) with a photo image running across all 4 boards.How do I set up the pages so I can see the whole composition together , then print the seperate A2 boards? Is it best to use Illustrator(CS3) or Indesign?
    Thanks.

    Re: I need to create 4 A2 boards that print adjacent to one another with a photo image running across all 4 boards.How do I set up the pages so I can see the whole composition together , then print the seperate A2 boards.Do I use illustrator (C3) or Indesign
    If possible, please try Indesign CS 4.

  • I have a big project but when im going to add a new clip with sound and picture in picture its only the sound that works. Can someone please help me?

    I have a big project but when im going to add a new clip with sound and picture in picture its only the sound that works. Can someone please help me?

    Also, if you can't get them to work, what is the error message you are getting?
    Baron Samedi

  • XOQ-01950: Cube contains multiple BuildSpecifications with the same name.

    Hi All ,
    While executing the Maintain Cube option it is throwing below issue : Any Clue ?
    XOQ-01950: The AWCubeOrganization for cube "NN_OLAP_POC.MARKET_SALES_CUBE" contains multiple BuildSpecifications with the same name.
    Thanks,
    DxP

    This error should only show up when you create a cube (by importing XML), not when you maintain it. So I will assume that this is what you mean.
    If you import XML that refers to an OLAP object that already exists, then the new definition overrides the old one. The only exception to this rule is the BuildSpecification object. This kind of object is named, but it does not follow these conventions (for messy implementation reasons). If you import XML that has a BuildSpecificaiton with the same name as one that already exists, then you will trigger the error you see. Here is an example of the relevant XML.
    <BuildSpecifications>
    <![CDATA[BUILD SPEC LOAD_AND_AGGREGATE
      LOAD NO SYNCH,
      SOLVE
    ) ]]>
    </BuildSpecifications>The workaround is to delete this section from the XML before importing it.

  • Add a new directory with hyphen (-) in the domain name

    Dear All,
    I'm trying to add a new directory with hyphen (-) in the domain name (default domain *.onmicrosoft.com). As a result I keep getting a validation error: "The domain is not unique". I've tried several
    combinations with really awkward words and a hyphen. Such domain names must be unique. I think that the error message is misleading.
    Is it a well known behavior? Is it possible to use a hyphen in the domain name?
    Thank you for your help,
    Artem

    Dear Arvind,
    Thank you for your effort and time in validating the described behavior.
    According to the
    Regexp for subdomain question on SO, 'Each subdomain part may contain hyphens (dashes), but may not begin or end with a hyphen'. That been said, the validation error, on your screenshot is appropriate. On the other hand, the validation error
    with a hyphen (dash) in the middle is misleading.
    It's not a big deal, since people most likely use a custom DNS name anyway.
    Kind regards,
    Artem

  • How to add a new table or view in the view object

    hello,every one.
    I wanna add a new table or view in the view object's query statement.
    when the table or view not in the where clause,the query statement is working fine.
    If they in the where clause,I got the "java.lang.NullPointerException".
    who can help me
    thank you very much

    thank you for your reply
    I wanna extend the VO
    oracle.apps.pay.selfservice.payslip.US.server.PayPayslipGetPersonDetail
    the original sql is:
    SELECT ppf.person_id,
    FROM per_people_f ppf,
    per_assignments_f paf,
    pay_assignment_actions paa
    where paa.assignment_action_id = :1 AND paf.assignment_id = paa.assignment_id AND SYSDATE BETWEEN paf.effective_start_date AND paf.effective_end_date AND paf.person_id = ppf.person_id
    I wanna extend:
    SELECT ppf.person_id, pay_v.element_name,pay_v.assignment_action_id
    FROM per_people_f ppf,
    per_assignments_f paf,
    pay_assignment_actions paa,
    pay_run_results_v pay_v
    where paa.assignment_action_id = :1 AND paf.assignment_id = paa.assignment_id AND SYSDATE BETWEEN paf.effective_start_date AND paf.effective_end_date AND paf.person_id = ppf.person_id
    pay_v.assignment_action_id =paa.assignment_action_id
    if the pay.v in the where clause. I will got the exception. whereas,it's works fine.

  • I had an iPod touch, but it was stolen or lost. Now that I have a new one with a new Apple ID, is there someway I can access and download all my old photos and data from my old Apple ID to my new device? I still remember my old Apple ID and password.

    I had an iPod touch, but it was stolen or lost. Now that I have a new one with a new Apple ID, is there someway I can access and download all my old photos and data from my old Apple ID to my new device? I still remember my old Apple ID and password.

    Restopre from backup
    To restore from backup see:
    iOS: How to back up     
    If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
    You can redownload most iTunes purchases by:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store        
    Also,
    - If you used PhotoStream then try getting them from your PhotoStream. See that topic of:
    iOS: Importing personal photos and videos from iOS devices to your computer

  • Hi guys n girls. How do you copy a whole table to create a new table with all cell sizes in tact? Thanks for your help. Jason.

    Hi guys n girls. How do you copy a whole table to create a new table with all cell sizes in tact? Thanks for your help. Jason.
    when you copy n paste into a new table, all the cell sizes are changed.
    is there a way to put in a new table from your templates into an existing file, different to the standard very basic ones in insert table.
    I look forward to your answers.  Your help is very much appreciated.
    Also how do you search for question answers already written in this support area please.

    Hi Jason,
    In Numbers 3, you can select a whole table by clicking once in the table to make it active, then click once on the "bull's eye" at the top left.
    Now copy and paste. All formatting (and any cell content) is pasted intact. In Numbers 2.3 (Numbers '09) it is a little different for selecting a whole table. But I won't go into that unless you are using Numbers '09. Please reply.
    I don't like the look of the tables in Insert Table. I keep custom tables in My Templates. I have set Numbers > Preferences > General > For New Documents > Use template: (name of my favourite custom template)
    That opens when I launch Numbers, or ask for a new document (command n). Note that if you follow this preference setting, then Menu > File > New From Template Chooser (for another template) requires you to hold down the option key in that menu.
    Regards,
    Ian.
    Message was edited by: Yellowbox. All formatting (and any cell content) is pasted intact.

  • I have changed settings on my email account with my provider, but in order to activate the address they instructed me to delete my account and add a new account with the same email address. Will this delete my all my email history? Any advise please?

    I have an OS X 10.6.8 and have had problems with my mail. I have changed my account settings with my mail provider, but they suggest I now delete my account and add a new account with the same email address. Will this delete my email history? Can anyone please advise?

    I have the same problem as the emails go to my iCloud account that I cannot access!!! I cannot answer the security questions as someone else must have set up my iCloud account. Nothing seems to work. It would be great if someone has some ideas as what can be done to recover the situation?

  • I have changed my Apple ID name and I want to change it on iCloud, however I am not able to delete the previous account because I need to turn off the Find my iPhone - and for that I need to log in with the old name and that is not working. Help anyone?

    I have changed my Apple ID name and I want to change it on iCloud, however I am not able to delete the previous account because I need to turn off the Find my iPhone - and for that I need to log in with the old name and that is not working. Help anyone?

    Hey tulgan,
    This link will provide information on what to do after you change your Apple ID:
    Apple ID: What to do after you change your Apple ID
    http://support.apple.com/kb/HT5796
    Welcome to Apple Support Communities!
    Take care,
    Delgadoh

  • Add a new table to an existing Print Layout Designer report

    Is it possible to add a new table to an existing Print Layout Designer report? For example, in the Production Order there is a Sales Order field (which is displayed on the report), I would like to display some information from UDFs found on the Sales Order, but when I add a Database Field to the report the Sales Order tables does not appear in the list (OWOR).

    Hi
    It is possible provided there is a relationship which exists between two tables.
    You can add a Database field. Goto the Properties and selct Content Tab.
    Now in the Table dropdown, hold the Alt Key and click. This displays all the tables in B1. After selecting the Table, you can select the related Column.
    Remember there should be a relationship which exists between this column and existing columns.
    Because PLD works completely on Joins to my understanding

  • I recently bought a new iphone 5s from UAE , but unfortunately i did not find the facetime on my new iphone, how come that i bought a new iphone with missing options , please help

    i recently bought a new iphone 5s from UAE , but unfortunately i did not find the facetime on my new iphone, how come that i bought a new iphone with missing options , please help

    Your earlier phone must have been originally intended for sale in another country and must have been purchased from somewhere other than an authorized Apple retailer. Phones that are intended to be sold in the UAE have FaceTime permanently disabled. The option is not there and cannot be made to work.

Maybe you are looking for

  • Help Required COMPLEX  MAPPING !!!!! POINTS WILL BE GIVEN !!

    Hii I am doing a file sender config and my message is something like this C1TN4028260000PP345700210 2620582 005 0000000000000072020061802 000000000000000000 C2TN402826000000001037331742557076 0000071641086338975600000110230000394007 C3TN4028260000000

  • Retriving .doc and .rtf files in soap attachments

    Please help me I'm using JAXM to retrive soap attachments When i retrive txt files (.txt) it retrivs the content of the document without any problem but when i try to retrive .doc or rtf it gives content as java.io.FileInputStream@587c94 (retrive att

  • Ldapseacrh command when upgrading to 10.1.2.3.0

    Hi Everyone, I am looking into upgrading my application server environment from 10.1.2.2.0 to 10.1.2.3.0. I noticed in the patch set notes in section 7.1.6 to run the ldapsearch command to see which middle tiers are using a metadata repository. I ran

  • Set variable offset

    Hello BI Experts, There is a variable zfisc in the selection screen to select the fiscal year single value. Once I have that I have to present values for zfisc-1, zfisc,zfisc1, zfisc2. How to do this ? Appreciate your suggestions. Regards, BWer

  • Can't upgrade CAMERA RAW in PS cs5

    Unable to updgrade Camera RAW in PS CS5.  have upgraded the application manager to no avail.