Questions tagged [sql-server-2012]

Use this tag for questions specific to the 2012 version of Microsoft's SQL Server.

3
votes
3answers
46 views

How to change column name when we are using case ? SQL Server query

I am trying to get result in one row using case statement it is showing me correct result but in two rows let me show you my query, select v.Id, v.VisitNumber, v.EndTime as VisitEndTime,...
1
vote
3answers
35 views

How to convert Row by row execution in to SET based approach in SQL

I'm working on a huge SQL code and unfortunately it has a CURSOR which handles another two nested CURSORS within it (totally three cursors inside a stored procedure), which handles millions of data to ...
1
vote
1answer
26 views

SQL query and troubleshooting

Good day to you all, I have a question regarding my sql query on rearranging the data. the query result look like this. Area | Name | Amount | Date 1 | N1 | 10 | 6/15/2019 2 | N1 | ...
0
votes
1answer
24 views

Generate binary matrix from series of csv strings in SQL Server (2012)?

Have a table of the form pk items -------- 1 a,b,c,... 2 d,e,f,... 3 g,h,i,... 4 j,k,l,... . . . where the items column values are variable length (can be empty) csv strings (whose elements need ...
0
votes
0answers
65 views

Preventing SQL Injection - CREATE Sequence Command

I have a very simple stored procedure which generates the next sequence as part of a simple Auto Number solution. The SQL store procedure is CREATE PROCEDURE [dbo].[NextAutoNumber] @Key varchar(...
0
votes
0answers
24 views

Sometime Sql Connection Error from windows forms-Network related instance error

Sometimes following error happening in windows application. The error is like A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was ...
0
votes
0answers
21 views

How can I Simulate string_agg function in old Version of SQL Server [duplicate]

I want to group by a table by some columns and show values of other column.in SQL v.2017 I can do that with string_agg function. but my SQL version is 2012.How can I do that... create table dbo....
0
votes
1answer
29 views

I have sql server hierarchical data table with this sample structure and data:

My table structure is: Id name size type parrent_Id 1 AAAA 2k t1 null 2 BB 2k t2 1 3 CC 1k t3 1 4 ...
0
votes
0answers
19 views

How can i make data insertions from SQL Server 2012 to Postgres and vice versa after an insert or update?

I have a database (BASE1) in SQL Server 2012 and i need create a copy after each insert and update made, then this copy must be updated into SQL Postgres (BASE1copy) I've searched and found: https://...
0
votes
2answers
35 views

Dynamic stored procedure to update a table

An application developer has asked me to create three different stored procedures to update the same table. Each stored procedure updates different columns and are called at different points in their ...
0
votes
0answers
22 views

Get column value dynamically from Inserted and Deleted table in trigger

Following is the requirement and approach/design taken Requirement: Need to insert into History table for an update on any column of a table, if and only if the value of the column has changed. Need ...
0
votes
2answers
36 views

MS SQL Server - Get Values Before and After a Delimiter

I’m trying to figure out a way to select specific values from a String that is separated by a delimiter, in this case commas. I need to report each value after a comma in a separate field. I’ll ...
1
vote
5answers
71 views

How to join two tables in one view?

I am trying to create a view where I can see the items that have been planned to be shipped and have not been shipped, and the items have have been shipped but were not planned to. In order to do ...
1
vote
2answers
36 views

How process JSON data that needs to be unpivoted?

I have a JSON source that has a weird layout where there are unknown amount of columns. https://theunitedstates.io/congress-legislators/committee-membership-current.json The format is like the ...
1
vote
2answers
65 views

Why the records are not getting pickets for the entry date?

I have written this query long time ago and it was working but now it's not. CREATE PROCEDURE [dbo].[WeeklyReport] AS BEGIN CREATE TABLE #temp ( Area VARCHAR(20), ...
0
votes
0answers
11 views

Retreiving result set of complex stored procedure joining multiple tables

I am very new to Spring JPA. I have complex stored procedure joining multiple tables. I want to use EntityManager.createStoredProcedureQuery(String procedureName, String... resultSetMappings) to ...
1
vote
1answer
24 views

How to update column with data from another table? - SQL Server 12.0.5

I am trying to update the column "efficiency" in the table "SUS_WK" with the data from the column "custom_number_8" from the table "SC_PROD". But I only want it to update if certain requirements are ...
0
votes
1answer
27 views

Is there any way to create range from table column with random value

I am trying to get a range in which a number will fall, the range will be the created from the values of a column of the table, for ex. let there be a column 'num1' which contains data (12,15,10,40,20,...
2
votes
1answer
58 views

SQL Server mismatch row count in SELECT and UPDATE query with same conditions

I am trying to match the update and select query count with same condition. but row count is coming with big difference. UPDATE Query: UPDATE MKP set MKP.Quantity = MKP.Quantity + LQD.Quantity, ...
0
votes
0answers
27 views

Remote connection to MSSQL 2012 is working but not from Local server

I have created a python 3.7.2 script to connect with MSSQL 2012 R2 Datacenter, I am able to connect with db from Remote that's from my Laptop and fetch the data in the table and saving it as xxxxx....
0
votes
0answers
61 views

CTE never ending execution when specifying a condition

I am facing a wild issue where a Common Table extraction takes very long to finish or apparently its not ending when we have specified a filtering condition in the select clause. But it runs fine or ...
-1
votes
0answers
8 views

Arithmetic overflow error converting expression to data type int but found no conversion issue

I am getting an error when execute this SP. The error says "Msg 8115, Level 16, State 2, Procedure dbo.sp_change_paswrd, Line 8 [Batch Start Line 2] Arithmetic overflow error converting expression to ...
0
votes
1answer
49 views

How Do I Split a Delimited String without creating a function or using the STRING_SPLIT function

Need to split a delimited string in the code without using the STRING_SPLIT function. This is in SQL Server 2016 running in compatibility mode 110 (SQL Server 2012), this unfortunately cannot be ...
0
votes
0answers
13 views

Logback DB issue SQL Server 2012.Issue with JDBC SQL driver. ERROR in ch.qos.logback.core.joran.spi.Interpreter - RuntimeException in Action

Not able to write the application logs to a SQL Server 2012 database using logback DB appender, as SQL dialect error is given with all versions of JDBC SQL driver classes. File appender in logback is ...
0
votes
1answer
24 views

SQL Pivot double sum

I have the following query result: dday showtime qty total 2019-06-03 Sat 22/6 - 2:30 PM 1 50.00 2019-06-03 Sat 22/6 - 7:00 PM 1 50.00 2019-06-04 NULL ...
0
votes
0answers
31 views

Show the next date (lead time) with multiple conditions

First to start off I introduce my first problem, that I solved, and then I explain the additional conditions that got added to the equation. I have a table with a unique index on Contracts of ...
0
votes
1answer
53 views

Multiple batches in a SQL transaction

I want to create several stored procedures (or user-defined functions) within a transaction. CREATE PROCEDURE statement must be the only statement in the batch, so I have to use following template: ...
-1
votes
1answer
39 views

Optimize sql query execution plan

I need to optimize queries for views, Below is one of query used in views: SELECT * FROM <tablename> WHERE (2=(SELECT value FROM dbo.version WHERE a=<somevalue>)) Although its showing ...
-1
votes
2answers
45 views

How to synthesize too many SQL calls into one

A vb.net desktop application must make hundreds of these calls on a SQL Server (2012). The declaration is composed in the application and requires hundreds (or sometimes thousands) of times from the ...
0
votes
1answer
26 views

Catch does not pass error_message() to remote stored procedure called inside catch

I created a small logging framework so I can easily call a stored procedure like spLog or spLogError. The stored procedures and tables all reside in a separate database called Logging. Now the code ...
-2
votes
2answers
46 views

How to remove spaces in a string field and insert into float datatype?

I have a varchar field with some data and I need to cast those values and insert into float data type field create table #tableTest ( someData varchar(100) not null ); insert into #tableTest(...
0
votes
1answer
35 views

Is it possible to have same SYSDATETIME result for 2 transactions

According to documentation, the precision of SYSDATETIME() function in sql server is approximately 100 nanoseconds. I have seen that just like GETDATE(), the SYSDATETIME function also returns the same ...
0
votes
1answer
49 views

append the query with custom data modifications to add more

I have table where i am getting 10 records, out of those 10 records, one of the record has a value of 0 or -110 & 3, those two records have the same ID, so i want to remove those 3 rows from the ...
1
vote
3answers
42 views

SQL Server stored procedure for updating a table in SQL Server 2012 with incorrect syntax error

I have the below stored procedure, and I am getting this error message: Incorrect syntax near '01' I have other stored procedures which begin with '01,' and they work ok. I'm not sure where the ...
0
votes
3answers
49 views

How can I search in month and year in SQL Server 2012?

I'm trying to write a query for searching for month and year only. What I made is searching for month. Can someone tell how I can modify this query to search for month and year like : 5/2019 or 5-2019 ...
0
votes
1answer
49 views

Connecting SQL Server with ASP.NET using Windows Authentication

I am getting below exception while connecting ASP.NET with SQLSERVER using below connection strings.i tried two methods. Exception An exception of type 'System.Data.SqlClient.SqlException' ...
0
votes
2answers
65 views

SQL Server - IsDate function returning unexpected result

I am trying to do something like this when ISDATE(u.NewValue)=1 then CONVERT(varchar,cast(u.NewValue as date),23) But sql server returns 1 for 2406 also as it is a date, so this select ISDATE('...
0
votes
2answers
11 views

sp_executesql parameter not recognized

I have a storedProcedure CREATE PROCEDURE dbo.Employee_GetEmployeeByID @employeeID int AS select EM.EmployeeID,EM.FullName, GM.Gender,EM.PhoneNumber from EmployeesMaster EM JOIN ...
0
votes
3answers
78 views

Need to run a stored procedure on all non system databases

I'm trying to loop through all non system databases and run a stored procedure. This stored procedure exists in all of the user databases. This is what I have found so far: DECLARE @command varchar(...
0
votes
2answers
81 views

Why am I obtaining these alter database error trying to create a DB using a DDL script obtained from SQL Server 2012 on SQL Server 2008?

I am pretty new to SQL Server, and I am finding the following difficulties. I extract the DDL to create a database from a SQL Server 2012 machine, then I run this DDL creating the database on an old ...
0
votes
1answer
51 views

Is it possible to make SQL query into .exe file?

I would like to know if it's possible to make SQL queries into .exe files so that when you run the .exe file, it runs the query. If not, is there a way to automatically run a query when certain table'...
1
vote
1answer
36 views

Duplicating Results when using Subquery, need to filter out Nulls and only show value if value exists

(Edited) I am having a problem with duplicating results when using a Count() Function and then Grouping by a column that changes from Null to having a value. See Below: Here is a sample table of data:...
-2
votes
1answer
71 views

How to solve this query statement?

Please, help me solve this SQL statement. I spent several days with this issue. I use SQL Server 2012. Level = N'First' --I use Unicode text SELECT ss.id, ss.SID, CONCAT(CONCAT(ss....
0
votes
0answers
26 views

SQLEXEC statement fails

What is wrong with this statement: lnResult = SQLEXEC(oGv.pnConnhandle, 'EXEC ClientSecurity.UsersCloneSP','userz') The stored procedure is qualified by a database schema name. Do I have to further ...
0
votes
1answer
36 views

[reflection.assembly]::LoadWithPartialName(“Microsoft.SqlServer.Smo”) not returning VersionString

I have the following powershell script that we run on many servers to retrieve the SQL VersionString: [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | out-null $srv = New-...
1
vote
2answers
57 views

Remove specific character from string (SQL Server 2012)

I have a view from which I want to remove a specific character in one of the columns. Specifically the character 'B' from the 'Fund' column below. I tried using the following version of TRIM ...
0
votes
1answer
25 views

I am trying to populate database with the image, image-name, image-number and image-price but only image column is filled

I am using angular as front-end and .NET Web API as backend and SQL Server 2012. I am trying to populate my database with image, image-name, number, and price but only the image is being populated. ...
-1
votes
3answers
32 views

Top 10 records with sum of remaining records in others in SQL server

I have one table which consists of 4 Columns - (id int, location varchar (max), [date] datetime, Total_Sales Money) which consist of 20 records in output I want 11 rows in which top 10 rows as it is ...
0
votes
1answer
26 views

How to turn this cursor operation into a set based operation on a closure hierarchy?

Trees.DirectReports is a closure (hierarchy) table. There is a table called Users with: RowID, EmployeeId, and MangerId. @RowCount is the number of records in this table and #EmpMgr is a cursor for ...
-1
votes
0answers
25 views

How to query multiple tables in SQL Server?

Student Register simple. Using SQL Server 2012. I have tables @tb_student1, tb_New_Reg, tb_parent and tb_class. School levels are Kindergarten, Primary and Child under 3 years. Kindergarten and ...