Questions tagged [t-sql]
Transact-SQL (T-SQL) is a dialect of SQL used by Microsoft SQL Server and SAP's Sybase.
3,121 questions
0
votes
0
answers
48
views
How to convert Oracle's TIMESTAMP(6) to a SQL Server data type
Question: How to store values such as 09/29/2015 4:58:47.000000 PM in a date type column in a SQL Server table?
Details:
Migrating data from Oracle to SQL Server. One column, say col1, in a table in ...
0
votes
2
answers
113
views
Grouping and arranging data using FOR JSON PATH and INCLUDE_NULL_VALUES
I'm having an issue with my T-SQL script. I am thinking about and working on how to produce the expected output from it.
Here's my T-SQL script:
DECLARE @user_id VARCHAR(50) = 'UGUID-2025-01-27-14-09-...
1
vote
1
answer
85
views
Multiple UPDATE and INSERT statements using BEGIN TRAN with customized COMMIT TRAN and ROLLBACK TRAN
First things first, since I am using SET XACT_ABORT ON. If an exception happens in any of the INSERT or UPDATE statements within the transaction block, then it should terminate and roll back the ...
4
votes
1
answer
411
views
Is it possible to extract the formula or expression of a field within a SQL Server Stored Procedure?
I have a stored procedure that contains a single select query. Within the query, there are a few aliases that represent a formula or expression.
Is it possible to extract the calculation / formula / ...
18
votes
2
answers
1k
views
Why SUM function returning 4 decimal places, but AVG function returning 6 decimal places
Question: Why SUM is returning with 4 decimal places (as expected), but the Avg is returning with 6 decimal places?
CREATE TABLE #t(Col DECIMAL(19,4))
INSERT #t VALUES (123456.1200),(654321.3400)
...
0
votes
1
answer
73
views
Database user must display only one database and one schema
I have a server on which there are 5 databases: A, B, C, D, E.
I need to create a new schema on database A called ‘rpt’. Then I need to create a new user called ‘usr_rpt’.
This user must have these ...
1
vote
1
answer
93
views
Convert numbered variables into a table row
I'm working with a legacy system where a stored procedure is called and dozens (literally) of variables are passed in. The data needs to be processed the same way but currently I have to copy/paste ...
0
votes
0
answers
38
views
Inserting range of IP's into a sql table [duplicate]
I have a sql table with two fields TermID and IP address. I want to insert(10.100.08.01-10.100.08.254) and each IP will have an assigned TermID for example (TERM1 - TERM254).
I will greatly ...
-1
votes
1
answer
89
views
Stored Procedure always returns null when using "RETURN value". If I use "SELECT value", it returns value correctly
USE [FPY]
GO
/****** Object: StoredProcedure [dbo].[insupd_tblMRBHistory] Script Date: 2024-12-19 7:25:36 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[...
3
votes
6
answers
578
views
Data sanitation options on INSERT or UPDATE
The answer in this post is pretty much what I did to get my problem:
SQL Server trigger before insert or update depend on value
I have a CUSTOMER table that has multiple triggers attached. One of ...
0
votes
2
answers
84
views
Handling Null in Dynamic SQL
I am trying to capture the existing CDC value and disabling and enabling again for partition truncate. I could not figure out how to handle null values in dynamic SQL.
If I directly pass @role_name ...
0
votes
2
answers
72
views
Query to flag user: SQL2022 Update is needed
My software, compatible with all versions of SQL2016 and up including SQL Azure, crashes when SQL 2022 is lower than Version 16.0.1135.2 or lower than 16.0.4165.4 - depending on RTM, GDR, CU (which I'...
1
vote
2
answers
62
views
Sql Server: Query to parse and validate codes
We have a #ValidCode table with list of valid codes like: 'A', 'B', 'C', etc. Another table called #SourceData with input data -- that comes as a combination of valid and invalid tokens (sometimes ...
1
vote
1
answer
42
views
how do I restrict users to execute SET QUERY_GOVERNOR_COST_LIMIT 0 in SQL Server
We had set up a server configuration of QUERY_GOVERNOR_COST_LIMIT to restrict expensive queries, but as it turns out some clients started using the statement :-
SET QUERY_GOVERNOR_COST_LIMIT 0
to ...
0
votes
1
answer
71
views
Get IDENTITY from source table and change not null of date while using select * into staging_table from table
I have a requirement where there are two main table involved one is staging table - DLSTYTOTAL data coming from other source RDBMS and another table is partitioned table -STYTOTAL_RAW where we are ...