Transact-SQL (T-SQL) is a dialect of SQL used by Microsoft SQL Server and SAP's Sybase.

learn more… | top users | synonyms

3
votes
1answer
32 views

A Customized Table with Chronological order

Goal: My request is the retrieve the return result from sp_Test as 8, 2, 4, 1 ,3 (take a look at picture 1) based on the chronological list from User-Defined Table Type dbo.tvf_id. Problem: When I ...
1
vote
1answer
41 views

How do I change name format in TSQL Query Result?

I have a simple tsql select query that returns a user's name in this format: e.g. Doe, John How do I update the output so that it is in the format John Doe? I have tried using a split string ...
3
votes
1answer
2k views

error in Execute SQL Task with parameter

I have an Execute SQL Task object in the Error handlers section of a SSIS package. What it does is inserting a record to a table using OLE DB connection. There is a value in the insert statement that ...
3
votes
2answers
48 views

Is there a less manual way of changing database properties for all databases in an instance?

I've recently audited a SharePoint server and found configurations that are against best practice. I'm hoping there is better and quicker way than right-clicking and changing these settings manually ...
-3
votes
1answer
8k views

What is the Difference between SQL Server 2008R2 and SQL Server 2014?

I want to take my project from SQL Server 2008 R2 to SQL Server 2014. But I want to learn what is T-SQL the difference between 2008 R2 and 2014 for Database Engine? I mean is there any end of life ...
0
votes
1answer
179 views

SQLcmd error 'Failed to initialize sqlcmd library with error number -2147467259'

I'm trying to update some maintenance plans to make use of the Ola Hallengrens IndexOptimize, but also mail the result of the operation using sp_send_dbmail. Old T-SQL: declare @indexQuery ...
1
vote
1answer
88 views

Sql Server Server Group query

Scenario I have 4 front-end sql server. All of them have the same db instances. Data are replicated from back-end databases. Issue In SQL Management Studio I have registered the servers and I have ...
0
votes
2answers
33 views

'Use <database> ' statement not executing T-SQL

Okay, this seems funny for a simple script: but I really need this small piece to execute well. DECLARE @dbName NVARCHAR(50) SET @dbName = 'rx_lab' DECLARE @SQL02 NVARCHAR(MAX) SET @SQL02 = 'USE ['+ ...
1
vote
0answers
32 views

Publishing Database Changes With SSDT that include Adding a New Column [closed]

Similar to Publishing database changes with SSDT that include altering data types of columns But I have the issue when I'm adding a new column to my database. I tried publishing incrementally by ...
1
vote
1answer
254 views

Joining multiple tables results in duplicate rows

I am running SQL 2005. I am getting more rows then I expect returned by my query. I believe it has something to do with my join statements. Here is my query: There are multiple tables that have ...
3
votes
3answers
1k views

T-SQL - How to split (char separated) string into rows and columns

What is the best way to split a char separated string into rows and columns? Here is my input string: !1;100;10;200;0;500;2;1000;30!2;100;3;500;1;2000;5 And here is my desired output table: Id ...
2
votes
1answer
63 views

Wrong results from joining two CTEs

I've had some help to create a query to solve a problem I had and the solution seemed to be to create two CTE's and then join and query them. If I run the two CTE's as single queries each table ...
2
votes
1answer
17 views

Retreive a Customized List with input data

I have a database that has about 223 tables and I need to locate the name of the constraint. My request is to add a parameter that is the name of the constraint and you retrieve a list that shows the ...
2
votes
3answers
234 views

How to use “BACKUP DATABASE”, but the database is in a different server.? [closed]

We have 3 servers ( SQL SERVER 2008 ). Is there a way to backup a database, connected in a different server? Example: i'm on SQL1. I want to do something like this: BACKUP DATABASE ...
0
votes
1answer
63 views

how to extract current year and combine with specific month and date as a date

I have to get the current year with June the 16th as a date. For example, if I run the query now I want to get 2015-06-16. I tried the following: CONVERT(DATETIME,cast( (cast(YEAR(GetDate()) AS ...
2
votes
1answer
203 views

Arithmetic overflow error varchar to numeric

I'm getting an arithmetic overflow error and I can't seem to find out the case. I've recently had to adjust some stored procedures, to allow for dates in the future to be put in. The following part ...
9
votes
2answers
6k views

How to optimise T-SQL query using Execution Plan

I have a SQL query that I have spent the past two days trying to optimise using trial-and-error and the execution plan, but to no avail. Please forgive me for doing this but I will post the entire ...
3
votes
1answer
106 views

Decode and aggregate a BitMask in t-sql

I have a table that contains a bitmask field that stores permissions, where each bit denotes whether a particular permission is granted or not. Here's a simplified example: DECLARE @T TABLE (id ...
-2
votes
2answers
206 views

SQL Server failed stored procedures log [closed]

How to find errors that was occurred in stored procedures in some timespan in Sql server management studio 2008 ?
0
votes
1answer
59 views

Some records are missing while selecting from table

I am trying to match the records having MAX(WORKITEM_ID) but some PROCESS_INSTANCE_ID are not coming though they are present in WORKITEM table. select WI.WORKITEM_ID as WORKITEMID, ...
0
votes
4answers
54 views

The multi-part identifier > “a.surveyid” could not be bound [closed]

I am getting the error : Msg 4104, Level 16, State 1, Line 1 The multi-part identifier "a.surveyid" could not be bound. Below is the query ,what could be the issue? SELECT a.surveyid,* ...
1
vote
0answers
56 views

SQL Server - Project based on the TDS protocol [closed]

From what I understand, TDS is an application level request/response protocol used for communication between a client and SQL server. Now, I'm in the process of finding a master thesis (computer ...
0
votes
1answer
101 views

How to modify maintenance plan using T-SQL script in SQL Server 2008

How can I modify a maintenance plan in SQL Server 2008 using a T-SQL script? I want to change the schedule of a maintenance plan and change the path of the .bak file . All these changes should be ...
0
votes
1answer
56 views

Which columns (and order) to choose for a clustered index to maximize query performance

In our database we have a table that looks more or less like the example below. In the past we always created the clustered index on the ID column on the table. CREATE TABLE [Measurement] ( [ID] ...
1
vote
1answer
66 views

DBCC DBREINDEX in MS SQL Server 2008

We have done DBCC DBREINDEX for our production database which size is about 300 gb, it was running for 12+ hours, but i found that DBCC DBREINDEX is obsolete and recommended approach is using ALTER ...
1
vote
0answers
562 views

time interval period in sql [closed]

How to display the time period of the most widely in use in ms sql server I have purchase data, such as: hours the number of purchases 10:00 2 12:00 4 13:00 5 14:00 1 ...
4
votes
1answer
143 views

SQL “Standard” guide?

I am currently learning TSQL and am learning that were possible, I should use "standard" SQL dialect. Where can I find out which commands are "standard" and which are TSQL?
1
vote
0answers
101 views

How to speed up for huge tables in SQL select query?

I have the following huge tables. Table_1 with 500000 (0.5m) rows Table_8 with 20000000 (20m) rows Table_13 with 4000000 (4m) rows Table_6 with 500000 (0.5m) rows Table_15 with 200000 (0.2m) rows ...
1
vote
2answers
66 views

How can I Insert when not in table and when max timestamp T-SQL

I am trying to insert rows from one table to another that are not in the one I am moving them to. I also want to only move the ones that have the highest datestamp. (I want to only insert rows that ...
0
votes
1answer
62 views

How to store a version sequence per product

I need to create a table like the following one: +----+---------+---------+ | Id | Product | Version | +----+---------+---------+ | 1 | 1 | 1 | | 2 | 1 | 2 | | 3 | 2 ...
0
votes
1answer
36 views

Script works but Im not sure this is the best format

I have a survey table which contains mostly integer. I want to make it readable for end user so I use select statement as below: SELECT CASE s.Country WHEN 1 THEN 'One' WHEN 2 THEN 'Two' ...
1
vote
0answers
41 views

Certification Test 70-461 [closed]

I am a student at University of Houston-Downtown and looking to take the Database Administrator certification test sometime in October. I am hoping that someone has been recently been certified or ...
5
votes
2answers
522 views

Symmetric difference operation in Transact-SQL?

I have always known about the UNION operator in SQL, but only recently discovered that there were other set operators, INTERSECT and EXCEPT. I haven't been able to find an operator that does the ...
11
votes
2answers
529 views

Help with PIVOT query

I have a table with below structure : CREATE TABLE [dbo].[AUDIT_SCHEMA_VERSION]( [SCHEMA_VER_MAJOR] [int] NOT NULL, [SCHEMA_VER_MINOR] [int] NOT NULL, [SCHEMA_VER_SUB] [int] NOT NULL, ...
1
vote
3answers
97 views

Can you Schedule a job inside another job?

I have many jobs that need to run but they cant run at the same time. the first step of each checks to see if any others are running if yes it waits a little bit and checks again. This can lead to a ...
-1
votes
1answer
130 views

How to merge same values in a column and rows

How can i merge same Stock item value and get the sum of both value in the table This is Query: select Invoice_TBL.InvoiceNo ,Invoice_TBL.ClientNo ,Invoice_TBL.ClientFullName ...
2
votes
0answers
41 views

Code required to make column not nullable

I have a table where I mistakenly allowed NULL values in a column: CREATE TABLE EXAMPLE ( EXAMPLE_ID INT IDENTITY(1, 1) NOT NULL, FOO_ID INT, CREATED_ON DATETIME DEFAULT ...
0
votes
0answers
16 views

How to Customized the Where Statement based on UDT

Goal: Display customized data based on customized where statement from UDT. The UDT is a parameter inside of a stored procedure. Problem: A parameter from a stored procedure is @communication ...
9
votes
1answer
982 views

Why 0 is equal to empty string?

I need some help in finding why the following T-SQL statement returns 1 (true): SELECT IIF( 0 = '', 1, 0) I guess someone has change an ANSI option like SET ANSI_NULLS or something else that is ...
5
votes
0answers
103 views

SQL Server - Best practices on debugging extremely complex stored procedures [closed]

I recently inherited a MESS of a search. It's around 10,000 lines of code in the procs/functions alone. This search is aptly named the "Standard Search." It's a proc that calls about 6 other procs, ...
1
vote
2answers
117 views

How to pull number code from strings buried in parentheses?

I have string data (ProductDescription) that includes product names and ID numbers and need to pull the ID numbers for cross-referencing... Data Samples: Widget (1234) Different Widget (123) Many ...
-2
votes
1answer
42 views

Usage of COALESCE? [closed]

Today: table abc a b c d ---- ---- ---- ---- 1 null 2 3 null null null 7 null 5 null 4 1 = e 7 = b 5 = f 3 = i 2 = w 4 = o The Goal is to retrieve this ...
2
votes
1answer
27 views

SELECTs in Database Change Log and Source Control

We are overhauling the way that we store our database in source control and keep a change log of it. I was reading the following article: http://thedailywtf.com/articles/Database-Changes-Done-Right, ...
1
vote
3answers
73 views

Load specific element from XML

I have the following xml: <root> <123 type="line"> <aa type="item"> <value>1</value> </aa> </123> <234 type="line"> <bb type="item"> ...
3
votes
1answer
182 views

How to union four different tables

I have two tables whereby both of them use sub queries. These two tables are combined by using UNION ALL. I have two other tables that only uses a WHERE clause and both of these are combined using ...
0
votes
1answer
33 views

How to serialize on SQL server metadata?

I tried to find an answer in Kalen Delaney's SQL Server Concurrency but there is no mention of metadata. The problem is how to ensure that only one of these reads and index creates executes from one ...
2
votes
3answers
767 views

SQL Server select columns which contain data

I'm working for a client to import data out of a generic off the shelf application database. If you can imagine a database that is designed by software developers that have no concept of database ...
2
votes
1answer
94 views

When using DBCC INPUTBUFFER to find query associated with spid, is there a way to show variable values of that query?

I have been troubleshooting an issue within a database that has some serious blocking issues. I found the command DBCC INPUTBUFFER a while back that allows me to see the query run for that spid. I ...
0
votes
0answers
25 views

Mass update taking to long [duplicate]

After searching through many posts I have come up with the code below to handle updating 200,000 to 2 million records daily. The problem is its still takes hours to complete, I have tried to narrow ...
0
votes
1answer
54 views

Stored Procedure Resultset Row Count and Resultset Size in Bytes/KBs

Is there any way to get total row count and size of result-set generated by a stored procedure execution? @@ROWCOUNT is a good option if its already added in each stored procedure but I just want ...