August 27, 2019 at 12:16 am
I have a Budget detail table with expenses and salaries projections. Some employee split the salary in two different account, I need a query that bring the expenses and the salaries which some of them are split into 2 accounts and the percentages of each split. I need to bring all budget informationΒ that is listed as "E" and employee salary information listed as "P".
CREATE TABLE Budget (
budget_type varchar (1),
a_gl1 varchar (6),
a_gl2 varchar(6),
employee_number varchar(10),
p_empl_proj_num varchar (6),
budget_req_amt1 int,
budget_req_qty1 int,
Description (50),
******************
Insert into Budget (
budget_type, account_id,
a_gl1, a_gl2,employee_number,
budget_req_amt1, percent,
Effective_date, emp_proj_num,
a_projection_no, Description)
values (P, 6252,
010470, 513120,
100015, 150000,
50, 10/1/2019,
2020, 0,
P, 6252, 010470, 514120,
100015, 150000,
50, 10/1/2019,
2020, 0,
P, 6252, 010470, 513120,
100016, 135000,
100, 10/1/2019,
2020, 0,
P, 6252, 010470, 513120,
100015, 140085,
100, 9/30/2019,
0,
P, 2568, 410900, 533120,
100050, 123270,
85, 10/1/2019,
2020, 0,
P, 2568, 450910, 535120,
100050, 123270,
15, 10/1/2019,
2020,
E, 2568, 012050, 502630,
15000, 10/1/2019,
0, Office supply
E, 2568, 013151, 492863,
80000, 10/1/2019,
0, Car maintenance
E, 6252, 032565, 568261,
85000, 9/30/2019,
0, Utilities)
August 27, 2019 at 12:23 am
Good start, but your query does not parse and you have not provided your desired results.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
August 27, 2019 at 12:43 am
August 27, 2019 at 1:34 am
August 27, 2019 at 1:40 am
Note to OP: please try running your own query. And then, please fix it so that it works π
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
August 27, 2019 at 10:45 am
hI pHIL
Insert into Budget (
budget_type, account_id,
a_gl1, a_gl2,employee_number,
budget_req_amt1, percent,
Effective_date, emp_proj_num,
a_projection_no, Description)
values (βPβ, β6252,β β010470β, β513120β, β100015β, β150000β, β50β, β10/1/2019β, β2020,ββ 0,β βNULLβ
βPβ, β6252β, Β β010470β, β514120β, β100015β, β150000β, β50β, β10/1/2019β, β2020β, β0β,βNULLβ
βPβ, β6252β, Β β010470β, β513120β, β100016β, β135000β, β100β, β10/1/2019β,β2020β,β 0β, βNULLβ
βPβ, β6252β, Β β010470β, β513120β,β100015β, β140085β,β100β, β9/30/2019β,β0β,β NULLβ
βPβ, β2568β, Β β410900β, β533120β, β100050β, β123270β, β85β, β10/1/2019β, β2020β, β0β,β NULLβ
βPβ, β2568β, Β β450910β, β535120β,β100050β, β123270β,β15β, β10/1/2019β,β2020β,β NULLβ
βEβ, β2568β, Β β012050β, β502630β,βNULLβ, β15000β, βNULLβ, β10/1/2019β,βNULLβ, β0β, Β βOffice supplyβ
βEβ, β2568β, Β β013151β, β492863β, βNULLβ, β80000β, βNULLβ,β10/1/2019β,β2020β, β0β, βCar maintenanceβ
βEβ, β6252β, Β β032565β, β568261β,βNULLβ, β85000β,βNULLβ, β9/30/2019β, βNULLβ, β0β, βUtilitiesβ)
August 27, 2019 at 10:52 am
To Create table:
CREATE TABLE Budget (
budget_type varchar (1),
Account_id (4) varchar
a_gl1 varchar (6),
a_gl2 varchar(6),
employee_number varchar(10),
p_empl_proj_num varchar (6),
budget_req_amt1 int,
percent int,
Effective_date (datetime),
Description (50),
August 27, 2019 at 11:04 am
Sorry everybody I was trying to edit my post but I cant
CREATE TABLE Budget (Β Β Β Β budget_type varchar (1), Β Β account_id (4) varcharΒ Β Β Β a_gl1 varchar (6),Β Β Β a_gl2 varchar(6),Β Β Β employee_number varchar(10), emp_proj_num varchar (6), budget_req_amt1 int,Β Β Β percent int, Effective_date (datetime),Β Β emp_proj_num varchar (6), Β a_projection_no (4) varchar,Β Description (50),
Insert into Budget (Β budget_type,Β account_id, a_gl1,Β a_gl2,employee_number,budget_req_amt1,Β percent,Effective_date,Β emp_proj_num,a_projection_no,Β Description)
values (βPβ,Β β6252,β β010470β,Β β513120β, β100015β,Β β150000β, β50β,Β β10/1/2019β, β2020,ββΒ 0,β βNULLβ
βPβ,Β β6252β,Β Β β010470β,Β β514120β, β100015β,Β β150000β, β50β,Β β10/1/2019β, β2020β,Β β0β,βNULLβ
βPβ,Β β6252β,Β Β β010470β,Β β513120β, β100016β,Β β135000β, β100β,Β β10/1/2019β,β2020β,βΒ 0β, βNULLβ
βPβ,Β β6252β,Β Β β010470β,Β β513120β,β100015β,Β β140085β,β100β,Β β9/30/2019β,β0β,βΒ NULLβ
βPβ,Β β2568β,Β Β β410900β,Β β533120β, β100050β,Β β123270β, β85β,Β β10/1/2019β, β2020β,Β β0β,β NULLβ
βPβ,Β β2568β,Β Β β450910β,Β β535120β,β100050β,Β β123270β,β15β,Β β10/1/2019β,β2020β,βΒ NULLβ
βEβ,Β β2568β,Β Β β012050β,Β β502630β,βNULLβ, β15000β, βNULLβ,Β β10/1/2019β,βNULLβ, β0β,Β Β βOffice supplyβ
βEβ,Β β2568β,Β Β β013151β,Β β492863β, βNULLβ, β80000β,Β βNULLβ,β10/1/2019β,β2020β, β0β,Β βCar maintenanceβ
βEβ,Β β6252β,Β Β β032565β,Β β568261β,βNULLβ, β85000β,βNULLβ,Β β9/30/2019β, βNULLβ, β0β,Β βUtilitiesβ)
August 27, 2019 at 12:31 pm
Do you even have SQL Server installed somewhere?
Because your code does not run. Even your modified code is riddled with errors. Here's a sample:
Really, you need to make sure that what you post actually runs in SSMS before you post it here and waste people's time.
Also, please format it in future to make it easier to read. Use temp tables, not permanent ones:
DROP TABLE IF EXISTS #Budget;
CREATE TABLE #Budget
(
budget_type CHAR(1) NOT NULL
,account_id VARCHAR(4) NOT NULL
--and so on
);
--INSERT statements here
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply