Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
154 views

Is it possible to pivot OPENJSON data for multiple rows in T-SQL (on SQL Server 2022). I have a case like below, it works fine for single ID (eg. CustID=111). Surely I can go this route processing ...
user1982778's user avatar
0 votes
0 answers
93 views

We have an End-to-End process which loads data into a Landing database. It used to run individual repopulate scripts for each data source in sequence, but that was taking more and more time to the ...
John Hunter's user avatar
0 votes
1 answer
89 views

I'm looking at the Networking settings for one or our Azure SQL servers, and I see some of them are greyed out. Azure Portal shows a message "You can use TSQL to remove or modify greyed out rules....
DinahMoeHumm's user avatar
2 votes
1 answer
87 views

We're using fulltext indexes in current builds of SQL Server and/or Azure SQL - compatibility levels well over SQL Server 2016 or higher, preferably SQL Server 2022 on Azure. While the searching in a ...
DinahMoeHumm's user avatar
0 votes
1 answer
85 views

I have a table valued function called "elara_customer_byname". When I execute SELECT * FROM elara_customer_byname('%Kar%') I get 2 rows, which is incorrect. If I copy the SQL from the ...
Karlton Kemerait's user avatar
-4 votes
1 answer
178 views

I found examples online using a recursive CTE to find all combinations of values that equal one target amount. The database column ledger_amount is DECIMAL(26,6). DECLARE @TARGET_AMOUNT DECIMAL(26, 6) ...
DoctorKennyG's user avatar
-8 votes
1 answer
127 views

Note that it's saved in time datatype. So if I have someone that started work at let's say 5:30 am and ended their shift at 10:00 am Is there faster way than: declare @Shiftstart time; declare @...
asri Allaham's user avatar
0 votes
1 answer
112 views

In SQL Server 2022, is there an aggregate function for doing a bit-wise OR against a particular column? -- Example table, data and output to show the different flags DECLARE @TEST TABLE (FLAGS TINYINT)...
freefaller's user avatar
  • 20.1k
0 votes
0 answers
38 views

I need to extract most keys/values separately, but also to collect the value of the entire 'wms' key into a single field. I am not the most experienced with OPENJSON(), so this is what I came up with (...
Chris Taliercio's user avatar
1 vote
2 answers
126 views

I have a group of tables being updated/replaced by an outside process. I need to add a primary key to make my queries run faster. However, if the column I'm using is nullable, it obviously won't be ...
Johnny Bones's user avatar
  • 8,502
0 votes
0 answers
61 views

On one of our databases, when I attempt to run sp_blitzCache, I receive the error: Error message is: The ''' character, hexadecimal value 0x27, cannot be included in a name. Procedure fails to ...
BMac's user avatar
  • 1
-1 votes
1 answer
67 views

I have two tables related to each other, each with roughly 200M records. CREATE TABLE [dbo].[AS_tblTBCDEF]( [CDEF_SOC_NUM] [numeric](5, 0) NULL, [CDEF_EFF_DATE] [date] NULL, [CDEF_TYP_BUS] ...
Johnny Bones's user avatar
  • 8,502
0 votes
1 answer
194 views

First, to define what I'm talking about, the "length" of a source is how many characters it has. Having more characters allows improving readability by using more descriptive function and ...
Vladimirs Kacs's user avatar
2 votes
1 answer
203 views

How can I select a service mark (SM) symbol in SQL? select CHAR(0153) --> ™ select CHAR(0174) --> ® select CHAR(0169) --> © What would the equivalent be for a SM symbol?
Jesse O's user avatar
  • 67
2 votes
2 answers
118 views

Take this for example: DECLARE @xml XML = N' <members> <member> <name>John</name> <age>32</age> </member> <member> &...
Miles Fan's user avatar
1 vote
1 answer
65 views

In a SELECT statement I want to convert .NET ticks to a datetime and display in Central Time. I don't want the timestamp+offset that "AT TIME ZONE 'Central Standard Time'" gives, I just want ...
Sam Clark's user avatar
2 votes
2 answers
186 views

I have a linked server named MyLinkedServer. The table I need to pull from has an XML column, so I can't just do SELECT * FROM MyLinkedServer.Database.dbo.Table due to known limitations with linked ...
Jeff Brady's user avatar
  • 1,546
2 votes
2 answers
134 views

My nvarchar value contains a control character - Start of Text (0x0002 / STX). I would like to include this in my XML value. Now I know XML is not tolerant of control characters so the only way I can ...
user31374527's user avatar
0 votes
1 answer
384 views

As mentioned in Unlocking the Power of Regex in SQL Server, SQL Server 2025 preview would contain new REGEXP_LIKE function. So I went to docker hub and grabbed the docker image with 2025 preview ...
Michał Turczyn's user avatar
0 votes
2 answers
183 views

In many SQL error messages, SQL Server does not mention column name. But in messages such as the one shown below, the error message does include the column name. Question: How can we extract the ...
nam's user avatar
  • 24.3k
0 votes
0 answers
101 views

I have an instance of SQL Server 2014. I have FTS index on my Customerstable. Everything works fine but I found that it can't handle short strings. For example: SELECT * FROM [dbo].[Customers] WHERE ...
Kliver Max's user avatar
  • 5,327
3 votes
1 answer
59 views

I need to extract data from a XML column in SQL Server 2016, for this example I'll create a XML variable, but in the real scenario the XML in inside a table so it is not editable. This is a sample of ...
FDB's user avatar
  • 1,112
-1 votes
1 answer
190 views

I need to select 10 to 20 random rows from a table. (I only can find how to select just N random rows). I need to get something like this SELECT * FROM table WHERE ABS(CHECKSUM(NewId())) % 19 BETWEEN ...
Kirik's user avatar
  • 15
1 vote
1 answer
82 views

I'm trying to import an XML file into a SQL Server table, there are no errors, but all values are 0 instead of the actual values. Could you please help me to understand what is wrong with my script? ...
Vladislav's user avatar
3 votes
1 answer
96 views

I am trying to import a legacy configuration file into SQL Server table that is in XML that also has an XSLT transform file. I have imported the XML config using .nodes and XPath syntax with a lot of ...
iFreeman72's user avatar
1 vote
1 answer
90 views

I have a number of system-versioned tables in my database. Microsoft notes here that... When you run any data modification queries on a temporal table, the Database Engine adds a row to the history ...
Leah's user avatar
  • 345
-4 votes
1 answer
135 views

I've been doing practice with the difference function in SQL, but I'm confused with some of the results. The statement is: SELECT id, fname, surname, DIFFERENCE(fname, 'matt') AS difference FROM table ...
Matt Bartlett's user avatar
-1 votes
3 answers
163 views

Say I have a list of orders that looks like this: OrderId CustomerId ItemOrdered OrderedWhen 1 1 Orange 2024-08-01 16:33:00 2 1 Apple 2022-01-28 01:00:00 3 1 Peach 2025-06-10 03:39:00 4 1 Banana 2022-...
Vaccano's user avatar
  • 83.3k
-1 votes
1 answer
70 views

I've got a column that stores text and I'm trying to find a way to pull the datetime from the field. I've tried to use a combination of SUBSTRING,CHARINDEX, and LEN to pull the datetime from the ...
MISNole's user avatar
  • 1,070
0 votes
3 answers
178 views

I have a table of Accounts: AccountID Name 1 Account A 2 Account B 3 Account C 4 Account D 5 Account E and a table of CurrentAccounts: AccountID 2 4 The desired result of combining these two tables is:...
SezMe's user avatar
  • 537
0 votes
4 answers
130 views

As expected, following code example 1 throws a primary key violation error in SQL Server table since I am inserting 2 twice in the id column. And the code does not enter any other values (1,3,4,5) ...
nam's user avatar
  • 24.3k
0 votes
0 answers
95 views

Using Activebatch's JobStep library, I want to run a SELECT query in the T-SQLBlock job step, and have the output of that written to a file using the WriteTextToFile job step. Is there actually a way ...
Josh's user avatar
  • 141
0 votes
1 answer
199 views

I am using a System ODBC Connection (64 bit) in a Link Server to Amazon Redshift on SQL Server. This works and returns data SELECT * FROM OPENQUERY (LINKSERVER, 'SELECT C1_FULL, C2_FULL FROM ...
Jmyster's user avatar
  • 1,003
1 vote
1 answer
148 views

I have an Azure Function built using .NET 8.0, which reads data from an Excel sheet and deletes all rows in Azure SQL Server, then adds around 67,000 new rows. I was doing this insert one by one with ...
microsoftdeveloperdesigner's user avatar
0 votes
4 answers
130 views

I need to remove duplicate values in a string but the string must have the same sequence. e.g. @string = "I need to remove duplicate duplicate values in a a string" must be converted to @...
Guus's user avatar
  • 63
-2 votes
2 answers
153 views

I want to truncate a datetime(7) at different lengths - determined by parts - in SQL Server 2019 (DATETRUNC starts on 2022 *). Kind of "year-month", "year-month-day", ... up to ...
altink's user avatar
  • 375
-1 votes
1 answer
126 views

I have an Azure function which read data from Excel sheets and update 3 SQL tables, and it clear 2 SQL tables before re-add the rows. On some scenarios, I will add the data as-is, while on another ...
microsoftdeveloperdesigner's user avatar
1 vote
2 answers
203 views

create table #t(col varchar(10)) insert into #t values(1042800) select col, ROUND(col,2) as RoundVal from #t update #t set col = ROUND(col,2) The select col, ROUND(col,2) from #t returns - as ...
nam's user avatar
  • 24.3k
-1 votes
1 answer
103 views

I have an Excel file with approximately 300k records and I want to delete these rows from a SQL Server table. I tried using INSERT for each record but that takes way too long. I also tried to create a ...
Breezeicti's user avatar
0 votes
1 answer
120 views

I'm monitoring my SQL Server environments (local setup, various versions like SQL Server 2017, 2019, 2022) and frequently encounter sessions that appear as sleeping but have sql_text and sql_command ...
Jvmnz_17's user avatar
1 vote
2 answers
119 views

My SQL table shows dates in US format. I would like to change them to show UK format in the table. My column datatype is smalldatetime. Existing SQL table format yyyy-MM-dd mm:ss I would like the ...
Danny's user avatar
  • 41
0 votes
1 answer
130 views

I have source data that looks like this: USER_ID STATUS_GROUP STATUS START_TIME END_TIME DURATION 52a3246f6 Available Available 2025-05-18 19:00:30 2025-05-18 19:01:13 43 52a3246f6 On_Queue Idle 2025-...
Sean's user avatar
  • 21
2 votes
1 answer
149 views

I can’t calculate subtotal and total using GROUP BY ROLLUP syntax in a SQL Server 2019 database: CREATE TABLE [dbo].[G_Dashboard] ( [orderId] int NULL, [C_CO] varchar(4) NULL, [D_CO] ...
the_uncle_vince's user avatar
-3 votes
1 answer
95 views

Currently I have hundreds of stored procedures that are in multiple servers, and that coexist with other stored procedures that are in other servers with linked server. The origin of this is that when ...
Angel Zapata Marquez's user avatar
0 votes
1 answer
134 views

I'm trying to use a cursor inside another cursor. I'm facing a problem that's: I'm only be able of update one row of all the millions of rows, and the others are considered as 'not found' which is not ...
Nelson Soares's user avatar
0 votes
0 answers
57 views

I am trying the following: declare @V_SQL nvarchar(4000); declare @v_formula nvarchar(4000); declare @P_RESULT Varchar(5) ; set @v_formula = '1 AND 0' ; set @V_SQL = 'BEGIN if ' + @v_formula + ' ...
altink's user avatar
  • 375
0 votes
1 answer
105 views

How to reduce clutter of data i.e. remove "duplicates per column" not "duplicates per row" i.e. type1 and type2 have no association. ID Type1 Type2 Type3 ... 1 A YY 1 A ZZ 1 B YY 1 ...
Glen's user avatar
  • 810
3 votes
1 answer
90 views

I'm using the modify() and query() methods to interact with XML data. Here is an example of how I'm using modify(): DECLARE @i int = 1 DECLARE @x xml = N'<?xml version="1.0" encoding=&...
Leah's user avatar
  • 345
0 votes
1 answer
109 views

In some languages (C# for example), you can coalesce to a throw expression, E.G. string someValue = MyFunctionThatMightReturnNull() ?? throw new Exception("null value"); Wondering if there ...
Mr Anderson's user avatar
  • 2,253
3 votes
1 answer
123 views

I have an application with the following requirements: Before a predefined event (in my application) occurs, I need to update and insert rows in different tables. After the event, certain rows in ...
MagicJP's user avatar
  • 85

1
2 3 4 5
1474