Web Analytics Made Easy -
StatCounter SQL Server: Query to #temptable - CodingForum

Announcement

Collapse
No announcement yet.

SQL Server: Query to #temptable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SQL Server: Query to #temptable

    Sir want to store the result of following SQL Server query into #table,

    Code:
    SELECT
    data.acc_code, 
    (case when sum(data.dr_amount) > sum(data.cr_amount)  then sum(data.dr_amount) - sum(data.cr_amount) end) as dr_amount,
    (case when sum(data.dr_amount) < sum(data.cr_amount)  then sum(data.dr_amount) - sum(data.cr_amount) end) as cr_amount
    from (
    SELECT acc_code,open_dr as dr_amount,open_cr as cr_amount from master
    union all
    SELECT acc_code,dr_amount,cr_amount from vouchers where date <[email protected]_date1
    union all
    SELECT acc_code,dr_amount,cr_amount from cashsalp where date <[email protected]_date1
    union all
    SELECT acc_code,dr_amount,cr_amount from crsalp where date <[email protected]_date1
    union all
    SELECT acc_code,dr_amount,cr_amount from brsalp where date <[email protected]_date1
    union all
    SELECT acc_code,dr_amount,cr_amount from mrsalp where date <[email protected]_date1
    union all
    SELECT  acc_code,dr_amount,cr_amount from orsalp where date <[email protected]_date1
    union all
    SELECT acc_code, dr_amount, cr_amount from frsalp where date <[email protected]_date1
    union all
    SELECT acc_code, dr_amount,cr_amount from srsalp where date <[email protected]_date1
    union all
    SELECT acc_code, dr_amount, cr_amount from cashprp where date <[email protected]_date1
    union all
    SELECT acc_code,dr_amount,cr_amount from crprp where date <[email protected]_date1
    ) as data 
    group by data.acc_code
    order by data.acc_code
    what codes should i use to store the result into temptable.

    please
    Last edited by guelphdad; Nov 26, 2016, 01:44 AM.

  • #2
    It's pretty clear you have a very bad database design. You might want to start with that first.
    To save time, lets just assume I am almost never wrong.

    The XY Problem
    The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

    Make A Donation https://www.paypal.me/KevinRubio

    Comment


    • #3
      Sir,
      bad database design?

      In what way?

      Comment


      • #4
        Look up and learn Database Normalization.

        You are repeating the same columns numerous times in numerous tables.
        To save time, lets just assume I am almost never wrong.

        The XY Problem
        The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

        Make A Donation https://www.paypal.me/KevinRubio

        Comment

        Working...
        X