Hi,
I need to merge 2 tables for the purpose of reporting on them.
1 table has actuals data that includes date, account type, branch location &
totals.
The other has budget figures which also includes business type, sub
catagory, date & budget amount.
Can someone explain how i could merge the 2 together.
I have attempted a union but get the error message operator must have equal
number of expressions.
here is the 2 queries
SELECT CONVERT(char(10), date, 103) AS Date, entity, entity_type,
sub_catagory, amount, comments, branch
FROM csd_budgets.dbo.tbl_budgets
WHERE (branch = 53) AND (sub_catagory = 2) AND (entity_type = 7) AND
(entity = 2) AND (date BETWEEN CONVERT(DATETIME, '2005-11-13 00:00:00', 102)
AND
GETDATE())
ORDER BY date
Thankyou in advance
Todd
SELECT CONVERT(char(10), date, 103) AS Date, Account_Code, Branch_Code,
Total_Balance, No_of_Accounts
FROM tbl_account_balances
WHERE (Branch_Code <= 56) AND (Branch_Code = 53) AND (NOT (Account_Code
IN (0001, 0004, 0006, 0085, 0808))) AND (CONVERT(char(10), date, 103)
= CONVERT(char(10), GETDATE(), 103))
and 2nd query isNot really clear on what you're trying to do here - if you use UNION
you basically stack a set of rows on top of another - column number
therefore must be the same...thus your error.
It sounds like you want to join the tables.
http://www.w3schools.com/sql/sql_join.asp|||In order to UNION 2 or more queries, the fields must match. UNION ALL will
give you the result you're looking for...I think...or just JOIN the tables o
n
a foreign key.
Just my twist on it,
Adam Turner
"Tango" wrote:
> Hi,
> I need to merge 2 tables for the purpose of reporting on them.
> 1 table has actuals data that includes date, account type, branch location
&
> totals.
> The other has budget figures which also includes business type, sub
> catagory, date & budget amount.
> Can someone explain how i could merge the 2 together.
> I have attempted a union but get the error message operator must have equa
l
> number of expressions.
> here is the 2 queries
> SELECT CONVERT(char(10), date, 103) AS Date, entity, entity_type,
> sub_catagory, amount, comments, branch
> FROM csd_budgets.dbo.tbl_budgets
> WHERE (branch = 53) AND (sub_catagory = 2) AND (entity_type = 7) AND
> (entity = 2) AND (date BETWEEN CONVERT(DATETIME, '2005-11-13 00:00:00', 10
2)
> AND
> GETDATE())
> ORDER BY date
> Thankyou in advance
> Todd
> SELECT CONVERT(char(10), date, 103) AS Date, Account_Code, Branch_Code
,
> Total_Balance, No_of_Accounts
> FROM tbl_account_balances
> WHERE (Branch_Code <= 56) AND (Branch_Code = 53) AND (NOT (Account_Cod
e
> IN (0001, 0004, 0006, 0085, 0808))) AND (CONVERT(char(10), date, 103)
> = CONVERT(char(10), GETDATE(), 103))
>
> and 2nd query is
>
>|||Tango-
I dint get whats ut exact requirement..but while using Union
Yor are getting error bcoz columns ur selecting while merging are not equal.
.
To override this ,
- Maintain the same columns in both select statements and if u dont want get
any columns from any of the table ,place 'null' instead of that column place
.
-COLUMN datatypes should be the same in both table while using Union/Union a
ll
Hoping this will help you
Kumar
"Tango" wrote:
> Hi,
> I need to merge 2 tables for the purpose of reporting on them.
> 1 table has actuals data that includes date, account type, branch location
&
> totals.
> The other has budget figures which also includes business type, sub
> catagory, date & budget amount.
> Can someone explain how i could merge the 2 together.
> I have attempted a union but get the error message operator must have equa
l
> number of expressions.
> here is the 2 queries
> SELECT CONVERT(char(10), date, 103) AS Date, entity, entity_type,
> sub_catagory, amount, comments, branch
> FROM csd_budgets.dbo.tbl_budgets
> WHERE (branch = 53) AND (sub_catagory = 2) AND (entity_type = 7) AND
> (entity = 2) AND (date BETWEEN CONVERT(DATETIME, '2005-11-13 00:00:00', 10
2)
> AND
> GETDATE())
> ORDER BY date
> Thankyou in advance
> Todd
> SELECT CONVERT(char(10), date, 103) AS Date, Account_Code, Branch_Code
,
> Total_Balance, No_of_Accounts
> FROM tbl_account_balances
> WHERE (Branch_Code <= 56) AND (Branch_Code = 53) AND (NOT (Account_Cod
e
> IN (0001, 0004, 0006, 0085, 0808))) AND (CONVERT(char(10), date, 103)
> = CONVERT(char(10), GETDATE(), 103))
>
> and 2nd query is
>
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment