TABLE player idPlayer | name | 1 | name1 | 2 | name2 | 3 | name3 | 4 | name4 | Table matches idMatch | idPlayer1 | idPlayer2 | date | 1 | 1 | 2 …
Tag: sql-server
Join two tables and concatenate multiple rows of a single field
Query: Current Output: Desired Output: I would like to join two tables, #Table1 and #Tabl2, on a key column, ID, and get Value field from the 2nd table… but in a single row (as shown in desired output). How (if possible) can I achieve the Desired Output? Thank you Answer For SQL Server 2017 and Later Ve…
Getting records with month by month, year by year and day by day from SQL Server
I’m looking for a fast and easy SQL Query to get records year by year, month by month and day by day. My database example: ID – DATE – CatID – VALUE 1 – 2013-08-06 – 32 – 243 2 – 2013-…
Distinct random time generation in the fixed interval
I’m trying to generate a random time between 8:00 AM and 8:00 PM for each row that is selected from a data set, however, I always get the same random value for each row – I want it to be different for each row. Table schema & data: Сurrent SQL statement: Current results (same time for each row in th…
SQL Server: round decimal number and convert to int (within Select)
I am using the following line within a Select which returns a number with decimals, e.g. 33.33333. How can I round this within the Select and convert to integers so that I don’t have decimals, e.g. in the above example it should return 33 ? Answer You can use ROUND function to round the value to integer…
Query database tables for missing link
I have two tables in my database and they each share the a field called cID. So here’s an example: Parent Table _______________ cID Name — —— 1 Record #1 2 Record #2 3 Record #3 …
Error dropping or deleting a user from SQL Server 2012
I’m trying to drop all the logins from SQL server except the default built-in SQL server logins but I’m unable to drop the “administrator” account. It gives me an error : “Server principal ‘…
Execute a Stored Procedure Inside a View?
I started working for a company a few weeks ago, and have inherited a crazy mess of databases. I’m currently working on designing the new systems to replace their older ones. The previous developer created a ton of views that are entirely identical, with the only differences being the conditions within …
Should I create separate SQL Server database for each user?
I am working on Asp.Net MVC web application, back-end is SQL Server 2012. This application will provide billing, accounting, and inventory management. The user will create an account by signup. just …
Compare two time strings in SQL
I have a string variable that denotes a time: I need to check if the current time getdate() is after or before @time. How can I do this in SQL? Answer This should do it: SQL 2008+ Earlier: