I want to to make to make the ordering in my query conditional so if it satisfiess the condition it should be ordered by descending For instance: Answer Don’t change the ASC or DESC, change the sign of the thing being sorted-by: The OP asks: Guys, I am not the SQL Expert, please explain me what means the id and
Tag: sql-server
Difference between CTE and SubQuery?
From this post How to use ROW_NUMBER in the following procedure? There are two versions of answers where one uses a sub-query and the other uses a CTE to solve the same problem. Now then, what is the advantage of using a CTE (Common Table Expression) over a ‘sub-query`(thus, more readable what the query is actually doing) The only advantage
How to combine date from one field with time from another field – MS SQL Server
In an extract I am dealing with, I have 2 datetime columns. One column stores the dates and another the times as shown. How can I query the table to combine these two fields into 1 column of type datetime? Dates Times Answer You can simply add the two. if the Time part of your Date column is always zero
Creating table names that are reserved words/keywords in MS SQL Server [closed]
Is it ok to name my database tables that are already keywords? For my case, I am trying to name the table that will hold my users. I’ve named it User but it is showing up as pink in SQL Server …
How to determine the number of days in a month in SQL Server?
I need to determine the number of days in a month for a given date in SQL Server. Is there a built-in function? If not, what should I use as the user-defined function?
How can I find duplicate entries and delete the oldest ones in SQL?
I’ve got a table that has rows that are unique except for one value in one column (let’s call it ‘Name’). Another column is ‘Date’ which is the date it was added to the database. What I want to do is find the duplicate values in ‘Name’, and then delete the ones with the oldest dates in ‘Date’, leaving the
How can I do a BEFORE UPDATED trigger with sql server?
I’m using Sqlserver express and I can’t do before updated trigger. There’s a other way to do that? Answer MSSQL does not support BEFORE triggers. The closest you have is INSTEAD OF triggers but their behavior is different to that of BEFORE triggers in MySQL. You can learn more about them here, and note that INSTEAD OF triggers “Specifies that
How to use a single SqlTransaction for multiple SqlConnections in .NET?
I have SQL Server 2000, it doesn’t support MultipleActiveResults. I have to do multiple inserts, and it’s done with one connection per insertion. I want to begin a transaction before all insertions and finish it after all insertions. How do I do it? Answer What is the reason you don’t use one connection and multiple commands (actually one command recreated
What are Covering Indexes and Covered Queries in SQL Server?
Can you explain the concepts of, and relationship between, Covering Indexes and Covered Queries in Microsoft’s SQL Server? Answer A covering index is one which can satisfy all requested columns in a query without performing a further lookup into the clustered index. There is no such thing as a covering query. Have a look at this Simple-Talk article: Using Covering
Difference between JOIN and INNER JOIN
Both these joins will give me the same results: SELECT * FROM table JOIN otherTable ON table.ID = otherTable.FK vs SELECT * FROM table INNER JOIN otherTable ON table.ID = otherTable.FK Is there …