analytics
22 TopicsSQL Query
Hi All, I have 2 tables ConfigurationTable and Data table. I require combine value like below output Source tables: Target Output: Sql Scripts: CREATE TABLE CONFIGTABLE(Productcode VARCHAR(10), Linkedvalue VARCHAR(10)) INSERT INTO CONFIGTABLE VALUES ('A', 'PEN') ,('C', 'PENCIL') ,('B', 'BOOK') ,('M', 'MOUSE') CREATE TABLE DATATABLE (FIELDVALUE VARCHAR(50), ORDERID INT,NAME VARCHAR(20)) INSERT INTO DATATABLE VALUES ('321', 9, 'COMPUTER') ,('THIS PEN IS', 1, 'A') ,('Country', 5, 'BOOK') ,('Great village in a', 4, 'B') ,('MINE', 2, 'PEN')Solved48Views0likes2CommentsDifference SQL Server 2022 vs 2017 Bind table
Hi, I'm Beginner SQL Server Engineer. I got some Question to SQL Server 2022, 2017 Bind table. During SQL Server practice, I heard that the bind table does not know statistical information, so there should be no IO reduction due to the index, but in the 2022 version, it seems that the index in the bind table refers to statistical information. something change between 2017 and 2022 Bind table?Solved76Views0likes2CommentsHow can I optimize this query for better performance
Hi , I have this query and it is taking a long time. If there are more than 10k rows, it takes more than 5 minutes. Is there another way to speed up the process? SELECT ROW_NUMBER() OVER (ORDER BY CreationDate DESC) AS RowId, Id [Id], transactionsId [TransactionsId], amount [Amount], AccountId [AccountId], dbo.Account_FirstBalance(CreationDate, AccountId, 161, CompanyId) [FirstBalance] FROM p_Ledger WHERE CreationDate >= '2024-11-01' AND CreationDate <= '2025-02-11' AND CompanyId = 117 AND branchId = 161 ALTER FUNCTION [dbo].[Account_FirstBalance]( @TransactionsDate DATETIME, @AccountId BIGINT, @BranchId INT, @CompanyId BIGINT ) RETURNS FLOAT AS BEGIN DECLARE @credit FLOAT; SELECT @credit = SUM(CASE WHEN T.transactionStatusId = 1 THEN T.amount ELSE -T.amount END) FROM dbo.Transactions T WHERE T.Approval = 1 AND T.CompanyId = @CompanyId AND T.AccountsId = @AccountId AND T.IsDeleted = 0 AND T.transactionsDate < @TransactionsDate AND (@BranchId = 0 OR T.branchId = @BranchId); RETURN ROUND(COALESCE(@credit, 0), 2); END;74Views0likes2CommentsHelp in Query to calculate the % from last two timelines
I want to compare the FAmt from last recent two lines and if difference is more than 80% then it should be in the result. The group/index keys are A,B,C,D, Edate. Create table #AR (A int, B char(10), C char(10), D char(10), Edate datetime, FAmt decimal (6,2), G char(2)) Insert into #AR values ('AA','CCC','1','E', '2022-01-01',12.60,'2') Insert into #AR values ('AA','CCC','1','E', '2023-01-01',15.80,'2') Insert into #AR values ('AA','CCC','1','E', '2024-01-01',18.60,'2') Insert into #AR values ('BB','DCC','1','E', '2022-01-01',11.40,'2') Insert into #AR values ('BB','DCC','1','E', '2024-01-01',15.60,'2') Insert into #AR values ('CC','DCC','1','E', '2021-01-01',12.60,'2') Insert into #AR values ('CC','GCC','2','E', '2022-01-01',15.60,'2') Insert into #AR values ('CC','GCC','2','E', '2023-04-01',18.60,'2') Insert into #AR values ('CC','GCC','2','E', '2024-04-01',34.80,'2') --Note: This FAmt is more than 80% from last timeline and it should be in the expected result Expected result: A B C D Edate FAmt G Comments CC GCC 2 E 2024-04-01 34.80 2 Current Amount is > 80% from last timelineSolved95Views0likes6CommentsHow to create view joining two table of similar records without duplicating.
Hi All, Hope all are doing great. I have a small query regarding the Join function to create view. I have two table in which table 1 is having 40k records and table 2 is having 40k records. But when i am joining the both to create view, it is showing 47k records. Please note that i am combining table using two common column in both, one is "Calendar_Date" and one is "Personal_ID". In some cases few Personal ID has duplicate records for each month. So while creating the view the, these duplicate records gets multiplied . Hence the total records exceeds 47k. How to make it same 40k records which i am having in each table. Any help would be highly appreciated. Regards, SagarSolved585Views0likes4CommentsNeed Help with SQL Server Express, Folder of CSVs and Power BI
Hello, I have a folder of CSVs that is updated daily. I want to get those into an SQL server and connect to Power BI. The reason I am going this route is Power BI currently just imports the CSVs and combines them, but it is killing the performance while working in Power BI Power Query. What is the best way to load and combine the files into SQL Server Express so I can connect the database to Power BI?Solved772Views0likes2Commentsunable to connect analysis service database
hi .. i am connected to analysis service database like this after connecting i create new empty database .. then i restore adventure.abf database into adve empty database by click right ---- restore database by clicking ok i got an error so after searching i grant permission .. and create new role DBAdmin and give all rights still no success.. how to resolve this issue help needed548Views0likes2CommentsSSMS Help - Capturing Changes in the data and recording
Hello Sorry in advance - I am new to SQL and SSMS. Please can I have some help with learning if the below is possible? I will have an SSIS package feeding data to SQL with the below table. The 'Report_Completion_Date' field is a write over field so if 'Client_ID' 1 completes a new report on 02/06/2023, the field will change from 01/06/2023 to 02/06/2023 when I next feed the data in on 02/06/2023. I can set up the SSIS package to inject data daily to capture any changes Client_ID Report_Completion_Date 1 01/06/2023 2 15/06/2023 I would like to capture any changes in the Report_Completion_Date field for any Client_ID's. My ideal output table will show the Client_ID and any or all Report_Completion_Date, unsure if it is best/possible to show the different Report_Completion_Date as additional columns if there is new changed data for Client_ID, for example: Example for new row everytime there is a new 'Report_Completion_Date' Client_ID Report_Completion_Date 1 01/06/2023 1 02/06/2023 2 15/06/2023 Example for new column everytime there is a new 'Report_Completion_Date' Client_ID Report_Completion_Date Report_Completion_Date_2 1 01/06/2023 02/06/2023 2 15/06/2023 Blank/Null Thanks so much for your help722Views0likes2Comments