1
to with a problem for SQL Server.
I have an event and value table and I make a Join with another table that has several columns, the amount can be marked as 1 for active and 0 inactive.
As you can see in the image line 1 has the RD8 , RD10 and RD21 marked, wanted the value of 97.24 to be demonstrated in lines but only for the RD’s marked.
She’d have to stay that way.
SQL de Criação
CREATE TABLE PFFINANC
(
CODCOLIGADA INT NOT NULL,
CHAPA VARCHAR (4) NOT NULL,
ANOCOMP SMALLINT NOT NULL,
MESCOMP SMALLINT NOT NULL,
CODEVENTO VARCHAR (4) NOT NULL,
VALOR RMDVALOR2 NULL,
)
CREATE TABLE dbo.ZMDCUSTO_PESSOAL
(
CODCOLIGADA INT NOT NULL,
CODEVENTO VARCHAR (4) NOT NULL,
RD1 BIT NULL,
RD2 BIT NULL,
RD3 BIT NULL,
RD4 BIT NULL,
RD5 BIT NULL,
RD6 BIT NULL,
RD7 BIT NULL,
RD8 BIT NULL,
RD9 BIT NULL,
RD10 BIT NULL,
RD11 BIT NULL,
RD12 BIT NULL,
RD13 BIT NULL,
RD14 BIT NULL,
RD15 BIT NULL,
RD16 BIT NULL,
RD17 BIT NULL,
RD18 BIT NULL,
RD19 BIT NULL,
RD20 BIT NULL,
RD21 BIT NULL,
RD22 BIT NULL,
RD23 BIT NULL,
RD24 BIT NULL,
RD25 BIT NULL,
RD26 BIT NULL,
RD27 BIT NULL,
RD28 BIT NULL,
RD29 BIT NULL,
RD30 BIT NULL,
RECCREATEDBY VARCHAR (50) NULL,
RECCREATEDON DATETIME NULL,
RECMODIFIEDBY VARCHAR (50) NULL,
RECMODIFIEDON DATETIME NULL,
PRIMARY KEY (CODCOLIGADA, CODEVENTO)
)
At first I’m making a Union all for each RD.. RD1 Union all RD2 Union all ....
– Vanderson
tried "unpivot"? https://docs.microsoft.com/pt-br/sql/t-sql/queries/from-using-pivot-and-unpivot?view=sql-server-ver15
– Motta
There is no way to model the database so that the columns become rows?
– Marcelo Shiniti Uchimura
Guys, I really know that modeling isn’t ideal. Unfortunately not or as good as wanted in Database then the modeling was horrible.. But the problem is fixed.
– Vanderson