Alternative approaches for Recursive CTE in SQL server. The data is 1 million records. need to calculate the current value based on previous value and iterate through Million records. Please suggest a methods which performs better than Recursive CTE
here is the query for your reference. Thanks! Alternative approaches for Recursive CTE in SQL server. The data is 1 million records. need to calculate the current value based on previous value and iterate through Million records. Please suggest a…
COALESCE and CONCAT Address Line 1 and Address Line 2 separated by a comma
We are trying to COALESCE and CONCAT Address Line 1 and Address Line 2 separated by a comma "," from potentially two data sources. So like...123 Main St., Apt. 101 The first part is easy enough... CONCAT ( COALESCE ( LTRIM (RTRIM…
How to get the current row value based on previous row value in sql server- ex first row has value, calculate the second row value using first row and some conditions and 3rd using 2nd row and same conditions
when basin <> prebasin, numberinbasinnew=numberinbasin. when basin=prebasin use the numberinbasinnew from the first row (basin<>prebasin) and calculate the second row value for numberinbasinnew based on below conditions -- CASE …
stored proc
Hello, I have a stored procedure which does the following: 1- filter tables and place data into #table1 2- filter tables and place data into #table2 ... Then at the end of the stored proc, select columns by joining these #tables. I have several stored…
Using Temporary Tables and Re-Using Temporary Tables in a SSRS Report
So we need to standardize Member Eligibility by using a SQL Server Stored Procedure that will be called, Executed by our Patient/Member SSRS Reports. The SQL Server Stored Procedure currently uses a Global Temporary Table to pass its result set back to…
SCOPE_IDENTITY() is Returning NULL instead of IDENTITY Value
Hello, I'm using dynamic SQL to insert a default value into a table and want to return the SCOPE_IDENTITY() value for my surrogate key. However, SCOPE_IDENTITY() is returning NULL for some reason. Am I missing something? Thanks for your…
slow query on large data
Hi there, --3billion rows of accumulated data over a period of time CREATE TABLE [dbo].[large_accumulation_table]( [amt] float(24) NULL, [lastdate] smalldatetime NULL, [type] [varchar](8) NULL, [doc1] [int] NULL, [line1] [smallint] NULL, [type1]…
Unable to debug Stored Procedure
I get the following error: Unable to start the Transact-SQL debugger, could not connect to the Database Engine instance. Make sure you have enabled the debugging firewall exceptions and are using a login that is a member of the sysadmin fixed server…
Microsoft SQL Server Studio - Dark Mode
Is there any official method to use Microsoft SQL Server Management Studio Studio with Dark Mode?
Record count difference during update query execution.
We are trying to update around 5 millions of data in Azure SQL DWH at a time. While updating the same it has been observed the count of records on table is getting frequently changed, until the update query is completed. What could be underlying reason…
changing the endcoding of an attached file in sql trasaction
Hi, I have written a sql server procedure which sends the result of a query as a csv file via e-mail. SQL server generates the attached file in UTF-8 BOM encoding. I need the attached file to be generated in UTF-8 (without BOM). I tried to…
SQL Server 2019 Instance Name Change
I am running SQL 2019 on Windows 2019 server and have come across an issue I have not seen before and cannot find a resolution on the web. I have went through the normal process of changing the Instance name by using the following.. EXEC sp_dropserver…
Database schema change of result in query sql server
How we can get database schema change result in query sql server? Is there any tool ? Suppose we do any change in schema. I want the result of that change in query.
Create JSON file and import as a table
Hi, This should be simple, but I tried various options and can not get it to work. I'm trying the following: SELECT TOP (100) ADMIN_AUDIT.admin_audit_id AS [id] , ADMIN_AUDIT.admin_audit_dttm AS [time] , ADMIN_AUDIT.process_txt AS…
loop through table records and execute Stored Proc with row data as params in sql server
Hi, I import data from csv file into a temp table. I need to loop through each row and call Stored procedure and pass that row details to the stored procedure as parameters. I know that it can be done using cursor and i have implemented it. I would…
Account ledger query with debit and credit
Hi All respected community member, i am trying to develop ledger query from long time still i could not get ,please do review and help me out , if you have any suggestion for restructure #tbl_Transection_test table ,please let me know or guide me…
Migrating existing packages - C# task is failing on a new server
Hi, We're migrating our SSIS server to a new server. Original server is Windows Server 16, SQL Server 2019. New server is Windows Server 2022 and OS is SQL Server 2022. We're getting the error on the packages that use C# script task: Code: 0x00000005 …
Maximum Length Exceeded
I am seeing the following error in my logs: EntityFramework.Exceptions.Common.MaxLengthExceededException: Maximum length exceeded ---> Microsoft.Data.SqlClient.SqlException (0x80131904): String or binary data would be truncated in table 'dbo.Profile',…
SQL Recursive query to generate output
Hello Expert , I am trying to generate one output as: Two different Tables: Table1: Cat1, Vol,Rank Cat1, 1, 1 Cat1, 4, 2 Cat1, 6, 3 Table2: Rank, Vol_Threshold, Partition 1, 21, 1 2, 27, 2 3, 34, 3 Would like to generate output: if running first…
How to covert UTC time to CST
I have a dataset recorded in UTC format. I want to covert it and add a field as CST. I used convert(datetime, switchoffset(convert(datetimeoffset, @UTCTime), datename(TzOffset, sysdatetimeoffset()))) to covert CST. However, I found it changed the time…