Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8480851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:24:26+00:00 2026-06-10T19:24:26+00:00

I have 2 queries where one query holds the parameters to be used by

  • 0

I have 2 queries where one query holds the parameters to be used by another query. I have done something similar, but not with multiple parameters. Here are the queries:

SELECT [loadJob]
      ,[loadStep]
      ,[parameter]
      ,[value]
  FROM [Admin].[admin].[LoadParameters] where loadJob like 'someJobName%' and (parameter = 'targetDatabaseName' or parameter = 'targetDatasetName' or parameter = 'targetDatasetSchema')

SELECT 
      TABLE_CATALOG as DB,
      TABLE_SCHEMA,
      TABLE_NAME,
      COLUMN_NAME,
      ORDINAL_POSITION,
      COLUMN_DEFAULT,
      IS_NULLABLE,
      DATA_TYPE,
      CHARACTER_MAXIMUM_LENGTH,      
      NUMERIC_PRECISION,
      NUMERIC_PRECISION_RADIX,
      NUMERIC_SCALE,
      DATETIME_PRECISION,      
      CHARACTER_SET_NAME
FROM 
INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_CATALOG = 'TheDataBase' // From the [parameter] with name 'targetDatabaseName' get form the [value] column
AND TABLE_SCHEMA = 'data' // From the [parameter] with name 'targetDatasetSchema' get form the [value] column
AND TABLE_NAME = 'TableName'  // From the [parameter] with name 'targetDatasetName' get form the [value] column

so if my results of the first query are:

[parameter]           [value]

targetDatabaseName    SomeDataBaseName

targetDatasetSchema   data

targetDatasetName     TheTableName

the where clause in the second query would use those parameters like so:

FROM 
INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_CATALOG = 'SomeDataBaseName'
AND TABLE_SCHEMA = 'data'
AND TABLE_NAME = 'TheTableName'

I would like to group everything by table name too so I can export it to a CSV. I tried a few things, but nothing I am proud to say would work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:24:27+00:00Added an answer on June 10, 2026 at 7:24 pm

    If you really don’t need the database, then you can use something like:

    with FirstQuery as (
        select max(case when parameter = 'TargetDatabaseName' then value end) as DB,
               max(case when parameter = 'TargetDatasetSchema' then value end) as Schema,
               max(case when parameter = 'TargetDataSetName' then value end) as table
        from (<first query goes here>) t
    )
    selelect <whatever>
    from Information_Schema q2 join
         FirstQuery q1
         on q1.Table_Schema = q2.Schema and
            q1.Table_Name = q2.table
    

    The problem that I see is the database. In SQL Server, the Information_Schema tables only contain infomation about one database. To get multiple databases at once, you may have to use dynamic SQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql query that uses union to join multiple queries into one
Sometimes I have to run multiple queries (one after another) with slightly different arguments
I have the following two queries which I want to get in one query.
I have three queries which I would like to consolidate into one query which
I have one query that i want to be fast, but there is somethings
I have two queries which both work but need to combine them into one
I have two queries. The first one is.. INSERT INTO balik ( balik_date, balik_time,
I have a problem to get to SQL queries into one, the problem is
I have these 2 queries that I would like to combine into one big
I have the following two queries, I believe that the one that uses the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.