Questions tagged [t-sql]

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

From SQL Server Books Online:

Transact-SQL is the language used to administer instances of the SQL Server Database Engine, to create and manage database objects, and to insert, retrieve, modify, and delete data.

Transact-SQL is an extension of the language defined in the SQL standards published by the International Standards Organization (ISO) and the American National Standards Institute (ANSI).

References

3091 questions
8
votes
1 answer

What is the difference between <> All and Not In

Could you please tell me the differences between select CustomerId from Customer Where TerritoryId <> All(select TerritoryId from Salesperson) select CustomerId from Customer where TerritoryId NOT IN (select TerritoryId from Salesperson)
June
  • 298
  • 1
  • 4
  • 15
7
votes
4 answers

Using IF statement after a WITH clause

I want to create an alias for a SELECT statement, but then I want to limit the resultset with a TOP clause. If the procedure TopCount parameter is bigger than 0, I want to put limit result set with TOP clause. But after the WITH clause, the IF…
uzay95
  • 173
  • 1
  • 1
  • 5
6
votes
3 answers

Dynamic database reference in T-SQL scripts

We have a set of databases (development, QA and production, dev-foo & dev-bar, qa-foo & qa-bar and just foo & bar respectively). Inside foo family of databases there's a view that should use respective bar database to do cross-database joins. In…
Anton Gogolev
  • 773
  • 1
  • 8
  • 13
6
votes
1 answer

Round-robin T-SQL problem with a twist

I have a table where I need to populate values, which are incremented using given step size. In addition I also have a notion of range, so that certain number of steps will fit inside the range (not necessarily evenly). Once the end of range is…
SQL_Guy
  • 665
  • 7
  • 18
5
votes
2 answers

SQL: TSQL to Find invalid views

we have a Tuesday/Thursday Maint window for one application we support. On Tuesdays we modify one facility and thursday if there are no errors we roll all the changes out to the other facilities. The application is 3ed party, and at times makes…
user1910240
  • 427
  • 4
  • 9
5
votes
2 answers

SET IDENTITY_INSERT inside INSTEAD OF INSERT trigger not working

I'm trying to perform a indentity insert inside a instead of insert trigger, but when I try to insert data into the data, it throws and error msg "Msg 544, Level 16, State 1, Line 36 Cannot insert explicit value for identity column in table…
5
votes
1 answer

Why does this query not use the index that exists on SURNAME?

There is an index on SURNAME in the PATIENTS table, we run the following query but the index doesn't get used. DECLARE @SURNAME VARCHAR(30) = 'test' SELECT SURNAME FROM PATIENTS AS PAT WHERE (PAT.SURNAME LIKE @SURNAME + '%' OR @SURNAME IS…
chris
  • 423
  • 4
  • 13
4
votes
1 answer

What is SQL/PSM and how does it differ from other versions of SQL?

I have searched SQL/PSM and I have learned that it stands for 'Structured Query Language/Persistent Stored Modules', but what I want to understand is what that really is and how it differs from T-SQL and any other versions of SQL?
3
votes
1 answer

Get records not updated in last 30 minutes

I am trying to write a script that will get records that have not updated the table in more than 30 minutes. Example records: DNS_NAME LAST_PERF_TIME esxnu01 2013-12-24 12:10:00.000 esxnu02 2013-12-24 12:05:00.000 esxnu01 2013-12-24…
Garry Bargsley
  • 571
  • 1
  • 5
  • 14
3
votes
2 answers

Filters Joins or Where clauses TSQL

Where should I put the filters on a TSQL query? SELECT a.colum FROM A JOIN B ON A.ID = B.ID AND B.STATUS = 1 OR SELECT a.colum FROM A JOIN B ON A.ID = B.ID WHERE B.STATUS = 1 I'm looking for performance issues or good practices.
Goows
  • 195
  • 1
  • 1
  • 5
3
votes
1 answer

MIN function returning multiple rows after adding column to SELECT

I'm trying to get the minimum value of Price together with product Description in the table ProductVariation. When creating my query this way: SELECT productId, MIN([price]) AS price FROM ProductVariation GROUP BY ProductId It works as expected,…
gregoryp
  • 135
  • 7
3
votes
1 answer

How to get identical values for different customers

I have a table which has different customers and each customer is having different insurance. say Customer Id Bank Account 1 Test insurance 1 1 Test Insurance 2 1 Test Insurance 3 2 Test Insurance 4 2 …
Sasi Dhar
  • 31
  • 1
3
votes
2 answers

Is long running query always more heavy than short running query

Perhaps a stupid question but since I don't know how the databaseengine really works under the hood I don't know the answer. More specifik I've learnt that the sql always tweaks the query so that it is the most optimized for the server. Not only…
user3532232
  • 129
  • 2
2
votes
1 answer

How to find the most common phrases in a varchar field

I have a table which contains support tickets. Each ticket has a title and many of them have common phrases in them (XXX cannot connect to YYY, XXX requires a new YYY, XXX requires upgrading, etc. etc.) I would like to do some analysis on the data…
Darren
  • 121
  • 3
2
votes
1 answer

Passing Table Values into a TVF

I have a TVF that takes a userID parameter. I have another table that contains a list of these userIDs. I want to pass all these userID values into the TVF. I have tried this code... FROM [dbo].[UserData](u.UserID) data JOIN dbo.Users u ON…
K09
  • 1,394
  • 13
  • 36
  • 59
1
2 3 4 5 6