Skip to main content
Filter by
Sorted by
Tagged with
-4 votes
1 answer
58 views

I've been tasked to write a query where a month and date combination from one column needs to not equal another date column. i.e. MED_EFF_DATE = 06/01/XXXX and MED_CANC_DT NOT EQUAL 08/29/XXXX I've ...
Johnny Bones's user avatar
  • 8,497
Advice
1 vote
1 replies
54 views

I am currently practicing SQL using the AdventureWorks sample database. Before posting, I tried searching but couldn’t find a structured collection of exercises specifically designed for practicing ...
tamta melkadze's user avatar
Best practices
0 votes
3 replies
64 views

I have a report application that i'm replicating. This report shows us 4 columns based on a date filter. Assembly Line, Product#, Enters and Exits. The Enters and Exits are time Stamps of when this ...
Marah Alsharaiha's user avatar
Best practices
0 votes
5 replies
113 views

What is the best way to alter a production SQL Server 18 table's column size, varchar(n +1). My understanding would be the following: Shut the website down to stop the transaction from coming in. ...
Piriformtest Piriformtes's user avatar
9 votes
1 answer
425 views

In a stored procedure (version 2019), renaming a column of a #table to a @value stops working for subsequent executions. The #table retains/gets the @value name of the very first execution. Is this an ...
user32064354's user avatar
3 votes
1 answer
127 views

Suppose the following is the select statement of a view SELECT Emp.ID, Emp.FullName, Emp.JoiningDate, Dept.DepartmentName, Reg.RegionName FROM Employees AS Emp INNER JOIN Departments AS Dept ...
Aftab Ahmed Kalhoro's user avatar
1 vote
3 answers
148 views

Suppose I have this table and values: DECLARE @TEST AS TABLE ( GroupId INT NOT NULL, ItemId INT NOT NULL, Ref1 NVARCHAR(10) NULL, Ref2 NVARCHAR(10) NULL ) INSERT INTO @TEST VALUES (1, ...
EMAW2008's user avatar
  • 351
1 vote
0 answers
52 views

I'm using ColdFusion Report Builder. I have an existing .cfr open. it has many properties (query.column_1, query.column_2... query.column_n) defined and used for display within the file. However, the ...
Jerome B's user avatar
3 votes
2 answers
193 views

I have recently investigated an audit table that had a wee bit of a bug with events that led to its data population, which I identified and fixed. Now there is the issue of past data that has ...
Steve Py's user avatar
  • 36.5k
0 votes
2 answers
171 views

Is there any difference (maybe in performance) between INNER SELECT filter and OUTER SELECT filtering: Situation 1 - INNER SELECT filtering: SELECT FROM ( SELECT ColA, ColB FROM myTable1 ...
sbrbot's user avatar
  • 6,565
Best practices
0 votes
5 replies
64 views

How to generate a conditional lag in T-SQL? If the visit is a D01 visit and VIS_DAT data is present -> retain VIS_DAT If the visit is a D01/D08 visit, and the VIS_DAT data is missing -> lag ...
Lizz's user avatar
  • 1
0 votes
2 answers
129 views

I run the below query against a view in MS Fabric environment (Data Warehouse). Here the compl_officer_id is the same across management_id partition (unfortunately there are no other unique values ...
muskagap88's user avatar
0 votes
2 answers
182 views

I need to join 2 tables based on a column named TRANS_ID. The problem is, one table has all available TRANS_IDs and the other table only has SOME of the available TRANS_IDs. For instance, take this ...
Johnny Bones's user avatar
  • 8,497
0 votes
1 answer
142 views

I am trying to use pivot, but it's not working the way I expect. The temptable I want to use input is #GenericTeam: Versionnumber Valid_from Team_name Attributenumber Attribute_displayname ...
Cees's user avatar
  • 35
0 votes
2 answers
83 views

I have a column of XML data in SQL Server that I'm trying to parse into columns. The start of the XML data looks something like: <DataSet xmlns="google.com"> <diffgr:diffgram ...
SomethingSomething's user avatar
0 votes
0 answers
61 views

I am getting incorrect results to a LIKE query when the like-string is defined as a NVARCHAR type parameter. The problem happens when including either brackets (span of characters) or underscore (any ...
Truncated's user avatar
  • 103
0 votes
2 answers
211 views

I have a TimeZones table that provides a list of all the time zones in the world with names, offset info, etc. I also have a CountryId column in my table which tells me which country time zones are in ...
Sam's user avatar
  • 31.1k
Best practices
1 vote
2 replies
119 views

What recommendations might be offered for the most elegant and performative way with T-SQL to evaluate whether a source value should update a target value, as part of an ETL update process in which ...
504more's user avatar
  • 505
Best practices
0 votes
4 replies
180 views

In SQL Server, I have a stored procedure that returns some sensitive data to the client, and logs that fact into a log table. The stored procedure is executed in a transaction controlled by the client,...
Branko Dimitrijevic's user avatar
2 votes
3 answers
216 views

Our integration team want to send a XML parameter from their Biztalk server containing values to be written to a SQL Server table using a stored procedure, and have sent me an example for me to create ...
Stephen Long's user avatar
0 votes
0 answers
55 views

I am trying to run a query in T-SQL to identify stored procedures that are defined with optional ("defaulted") parameters. I had expected this to be a common thing for people to try and find ...
DinahMoeHumm's user avatar
  • 1,120
1 vote
1 answer
223 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
121 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
1 vote
1 answer
380 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
  • 1,120
2 votes
1 answer
109 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
  • 1,120
0 votes
1 answer
91 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
192 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
140 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
124 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
1 vote
2 answers
145 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,497
0 votes
0 answers
93 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
81 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,497
0 votes
1 answer
207 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
4 votes
1 answer
255 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
  • 87
2 votes
2 answers
124 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
70 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
202 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
168 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
571 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
205 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
107 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
62 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
194 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
88 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
119 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
105 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
  • 355
-4 votes
1 answer
169 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
170 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.5k
-1 votes
1 answer
77 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
203 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

1
2 3 4 5
1473