Questions tagged [sql-server-2012]
Use this tag for questions specific to the 2012 version of Microsoft's SQL Server.
16,908
questions
0
votes
0
answers
23
views
CAST to TIME in select query is taking long time to execute
declare
@fromLocalTime TIME = '06:00:00',
@toLocalTime TIME = '06:59:59',
@runDate AS DATETIME2
SET @runDate = GETUTCDATE()
DECLARE @notificationCreatedFromDate AS DATETIME2 = (SELECT DATEADD(day, -1,...
0
votes
0
answers
26
views
SQL Pivot table not working in SQL SERVER 2012 [closed]
I am trying to aggregate data in SQL server 2012 but having problems.
I have the table like the one below:
type
id1
id2
Low
12
3
Low
24
3
High
11
3
Mid
25
4
Low
11
3
High
38
3
High
12
6
Mid
...
0
votes
0
answers
21
views
tSQLt testing between source and destination database
I have data loaded from Oracle DB to SQL Server every day via SSIS job. I have asked to verify in tSQLt whether a number of records on oracle DB loaded correctly in SQL Server. How can I do this ...
0
votes
0
answers
37
views
DISTINCT with HASH MATCH (Flow Distinct) in SQL Server
Recently, while working in SQL Server, I got an interesting thing that removing DISTINCT keyword actually decreased my query performance and increased my search time.
I read that DISTINCT can make ...
0
votes
1
answer
28
views
How do I do a multiple level Nested Loop Join?
I'm sure this must be a common coding question, but I don't even know what to call it.
For any given Person, I want to find their team - now there may be teams inside of teams, or maybe there are not -...
0
votes
2
answers
49
views
Pivot data based on category and date field
I have to identify the records with check_in category of S1, T1 and P1 in the check-in-order and pivot the rest of the data until we hit the next category. I was able to mark the category but was ...
-1
votes
1
answer
46
views
Find date gap between two events based on other column condition
I have a Dataset like below :
How can I find the time gap by day between the first hire date and terminated date for each employee No and show the result within a new column called FinalTenure in ...
-2
votes
2
answers
42
views
Remove part of a string after a character until a charcter and repeat until the string end
I am trying to filter part of a string until it reaches a specific character and repeat until the end of string.
Data loooks like
095930
CF0010+EN
060983+PS
086588+GG;086326+GG
900010;
CF0002;;CF0018;
...
1
vote
1
answer
30
views
SQL find products sold in business days
I'm trying to find number of products sold in +/- 5 business days from a particular date. I have a utlitiy function which tells whether the date is business day or non business day but I'm unable to ...
-2
votes
1
answer
23
views
convert varchar to INT SQL -Conversion Failed [duplicate]
I am trying to convert varchar to Int and i tried cast, convert, try_cast but getting an error conversion failed when converting varchar to datatype INT.Any other way to convert it?
select cast('123RA'...
0
votes
0
answers
17
views
SQL Server remote access via Entity Framework
There are two physical servers. A managed Linux server (the server on which the application is hosted) and a Windows unmanaged server on which the database is located. I access the database with EF.
...
0
votes
1
answer
18
views
SQL Server Database Publish Profile not using configured property
We have a database project for our SQL Server 2012 database. This database has a few SQL CLR assemblies which are very rarely updated that I wish to exclude from an automated dacpac deployment. I ...
0
votes
1
answer
58
views
Converting GMT to EST in SQL Server
I have a table which stores records for Daylight saving and non-Daylight savings
CREATE TABLE #tmp
(
ID int,
IntervalName nvarchar(100),
StartDate datetime,
EndDate Datetime,
...
-2
votes
2
answers
34
views
Use list of values in procedure
I'm trying to create a stored procedure to update a row with a list of pre determined values for example:
CREATE PROCEDURE updateNaturePassword(@_email AS VARCHAR(256))
AS
DECLARE
SET @...
-2
votes
2
answers
52
views
Find text in between 2 strings
I have the following code which works for finding text in between 2 strings. I need help with finding text between multiple occurrences. In this case, I am trying to find text between start and end. ...
-4
votes
1
answer
60
views
SQL IN operator is not working with multiple value of scalar variable in C# Winforms
I have facing a problem that SQL IN operator did not work with multiple value of scalar variables in C#, but query works in SQL Server 2012.
This is working:
SELECT WorkStatus
FROM viewWorkRequest
...
-1
votes
3
answers
38
views
Is there a way to check that none of the rows in a grouping contain a value?
I have a query that looks like this:
SELECT ordDetails.OrderId
FROM orders.OrderDetail ordDetails
WHERE ordDetails.Class <> 'O'
GROUP BY ordDetails.OrderId
But this does not work quite ...
0
votes
0
answers
25
views
Need to get the deadlock logs in SQL Server for yesterday
I am trying to use the query below for getting the xml report for deadlocks for the current day.
DECLARE @xelfilepath NVARCHAR(260)
SELECT @xelfilepath = dosdlc.path
FROM sys....
-1
votes
0
answers
26
views
Error on SQL event notification in SQL Server Database
Please help to disable notifications in SQL Server.
Long time ago, DDL event was created to audit DDL activities in database. Then alert was disabled because of uselessness and related job also was ...
-2
votes
2
answers
39
views
T-SQL calculation with a CASE statement isn't working [closed]
I'm scratching my head over this. I'm sure it's something simple, but I'm stumped. I have the following T-SQL, which I'm running in SQL Server 2012:
DECLARE @MAX_naam AS varchar(MAX) = (SELECT ...
1
vote
1
answer
46
views
SQL Update duplicates ordered by specific date
[table] is a table which I parse once a minute, and I am updating the oldest records with 'in progress'. When I am done processing, I delete the 'in progress' records and start over. My rare issue is ...
1
vote
1
answer
61
views
SQL Change an UPDATE to skip duplicates
[table] is a table which I parse once a minute, and I am updating the oldest records with 'in progress'. When I am done processing, I delete the 'in progress' records and start over. My rare issue is ...
0
votes
0
answers
37
views
How to query a subset in SQL Server?
The table I'm querying has two different kinds of contracts mixed up, 'a' and 'b%'. I need to query up the users who have both types of contracts expiring 60 days before getdate() and 20 days after ...
2
votes
2
answers
50
views
SQL Query to sort date based on two column
I have following data in table RATING and i want to sort this based on Rating and Year.
Database MS SQL Server
Unsorted data in Table
ID PlayerName Rating Year
1 A 8 2022
2 B 8 ...
-2
votes
1
answer
34
views
Compare two string char by char and highlight the different ones
I need a function that will take 2 strings and return the second one with highlighted mismatched characters with html code.
For example:
dbo.function('Jack', 'jake')
will return a string:
'ja<font ...
-1
votes
0
answers
34
views
On cascade delete not deleting [duplicate]
I have the usual order->orderline setup
t_ordrer.id (primary key) = t_orderdetaljer.ordreid
So I expect when I delete an order, the order lines should dissapear too. But they don't. I get no error ...
0
votes
1
answer
37
views
Non English characters not inserting from file to SQL Server in C# application
We have this table
CREATE TABLE [dbo].[PackageStatus]
(
[ID] INT IDENTITY (1, 1) NOT NULL,
[PackageStatusName] NVARCHAR (200) NOT NULL,
[...
0
votes
2
answers
52
views
Exec tSQLt.Faketable crashing our original table constraint and data
During debugging the tsqlt code, I have directly run the below statement without wrapping it as sp and my original table constraint got deleted and some data missing from the original table.
Exec ...
0
votes
0
answers
23
views
SQL Custom Log Process Tracking
I make some processing using a stored procedure and will be run sequentially using scheduler later.
Now I want to make process tracking using TRY CATCH block and insert the process status, either ...
0
votes
1
answer
50
views
Return 0 if no row found in SQL Server using Pivot
Thanks everyone, and thank you @Aaron Bertrand, your answer solved my problem :) !
i am struggling to find a solution to my problem, here is my query in SQL Server :
EDIT: a little more details : this ...
2
votes
1
answer
65
views
How do I effectively diagnose a 'wait operation timeout' on SQL Server 2012 database insert?
I have a C# windows service that is writing to a SQL Server 2012 database with an exec sp_executesql call.
exec sp_executesql N'Insert into [table name redacted]
(trial.[field redacted],trial.[field ...
1
vote
0
answers
52
views
CONVERT fails but TRY_CONVERT successfully convert same data
I have a column with dates stored as strings (NVARCHAR(500)), in dd/MM/yyyy format.
This query gets all rows with a non null value in my date_column, 13955 rows returned, 18359 total rows on table.
...
0
votes
1
answer
70
views
How do I convert datetime hour part from 24 hour format to 12 hour format in SSIS expression?
I want to convert the current time's hour part from 24-hour format to 12-hour format. I need output in SSIS expression as the below query gives in SSMS.
SELECT '0'+CAST(DATEPART(HH,GETDATE()) AS ...
0
votes
0
answers
22
views
When does SQL SEQUENCE CACHE reset
Here's the SQL sequence:
CREATE SEQUENCE [dbo].[ColumnID]
AS [bigint]
START WITH 1000
INCREMENT BY 1
MINVALUE -9223372036854775808
MAXVALUE 9223372036854775807
CACHE
GO
This is used to auto ...
-2
votes
1
answer
45
views
Simplify Query SQL
I have a query like:
--FIRST QUERY
SELECT a.EmployeeId, a.Seq, a.EmployeeAddress
INTO #Address
FROM Address a
WHERE a.Seq = 1
--SECOND QUERY
SELECT a.EmployeeId, a....
0
votes
0
answers
85
views
Microsoft OLEDB Provider for SQL , DateTime2 is added as DateTime
I am using SSL from now on so I moved from the integrated SQL OLEDB (MDAC) to the Microsoft OLE DB Driver for SQL Server.
And I was hoping that suddenly datetime2(7) would work. But unfortunately I ...
0
votes
2
answers
65
views
Need to get the value from a column whose column name is based on a value in another table
Table A has columns ID, COL1, COL2, COL3.
Table B has columns AID, ColumnName.
I need to get the [ColumnName] value in Table A based on the value of [ColumnName] in Table B.
In the example below:
For ...
-4
votes
2
answers
45
views
split one column values into multiple column based another column value
could you please help me writing select query to get expected output from the below picture. what I want is to split the UPC column values into three columns(Bottle UPC, Pack UPC, Case UPC) based on ...
0
votes
0
answers
33
views
In SQL Server I have Json format rows in column level need to create multiple columns # fields are not order we can create based on that
{zipCode=47715, state=IN, city=Evansville, countryCode=US, line1=7424 Eagle Crest Blvd}
{zipCode=10965, state=NY, city=Pearl River, countryCode=US, line1=One Blue Hill Plaza}
{zipCode=30339, state=GA, ...
0
votes
1
answer
65
views
About SQL pivot table
I'm trying to figure out how to produce this result in SQL using pivot table Sorted by SubID
units
Sub
SubCode
AM
PM
3
Math
M2201
Monday / 7:00AM-8:00AM
Tuesday / 1:00PM-2:00PM
3
Science
S2203
...
0
votes
3
answers
46
views
Using Liquibase to manage two types of DBs and generate build/deploy scripts
My local deployment application supports 2 database types (Oracle and MS Sql Server). I have a working system with a set of build scripts that can be run against an empty schema to create a new build. ...
-2
votes
1
answer
121
views
Is there a loop function which can automatize this?
I have these lines of code which you can find below and I want to automatize this (most probably using a loop function) by just giving the input: 'CITY', 'COUNTY', 'PARTNERS', 'PRODUCT'. Is there any ...
-1
votes
2
answers
71
views
Trigger causing Maximum trigger nesting level exceeded
I have created a new trigger that updates my [Purchase Table] if the number of delivered items equals the ordered quantity, but every time it's run I get the following error.
ODBC--update on a linked ...
0
votes
0
answers
26
views
Use Single Server to run SQL Server Agent Jobs for all environments
We have a dedicated server to run SQL Server Agent jobs for each environment (ie., DEV, QA, STG,...). We almost have 20 environments.
Looks like the table below.
So currently we have 20 servers for ...
-2
votes
2
answers
35
views
Return Date Ranges based based on a given interval between two given dates in SQL
I am trying to get a list of all DateRanges of a given interval between two dates.
For example if I have the dates 2015-04-01 and 2015-06-20 and when the interval is 20 the result should be
DateFrom ...
0
votes
1
answer
48
views
Get all month ranges in given date range in SQL
I am trying to implement a below scenario
I have two dates like below
declare @start DATE = '2011-05-21'
declare @end DATE = '2011-08-17'
My requirement is to generate a table like below based on ...
0
votes
2
answers
52
views
case statement to find if qualification has expired
I need to workout if someone's qualification has expired. Once someone has completed a course it expires in 3 years from the date of completion. If their qual has expired but they have a nominated ...
0
votes
0
answers
11
views
How to get DDL Binary value?
so I'm creating SQL assemblies and I have problem trusting my DDL.
So to trust my DDL, I need to get it's binary value and covert it using hashbytes.
Example "0x45DA90000036153900000....."
...
2
votes
1
answer
81
views
Round Robin Ticket Assignment in SQL with limit of active tickets?
I have to assign the tickets to employees in a round robin fashion with a threshold of 5 tickets to an employee.
Employees should not have more than 5 active tickets. While assigning the tickets we ...
1
vote
1
answer
28
views
SQL Help, Splitting Tax by Tenders
I have a Point of Sale system where all checks and tender details exist in a single table. I'm trying to write a SQL query in a way that I can see check totals by tenders to reconcile with cash flow ...