Using SQL Server Management Studio 2012, I’m trying to create a copy of a local database. I found a few variants of solution. One of them – backup and restore database as new one – HERE. Currently create database backup with name Rewards2_bak. This copy of file place in to system catalog C:P…
Tag: sql
How to replace empty spaces with NULL
I have a column in sql server 2012 which contain white spaces. I want to replace these empty spaces with NULL. I have written the following query but its not working. How to achieve the above functionality. Thanks in advance. Answer Use nullif
Is there a T-SQL command that checks whether the object to which a synonym refers exists and is valid?
I’m trying to test if all synonyms on a database refer to valid objects, using the SQL batch script below, as part of a clean-up effort on our databases. This script just performs a query against the synonym, and printing out any errors it encounters. This works fine on views and tables, but not on spro…
Finding max value of multiple columns in Sql
How can I find maximum value on multiple columns. This is what I have so far. This code is giving me the error: Incorrect syntax near ‘maxval’. Answer Are you simply looking for GREATEST? However GREATEST Returns NULL when a value is NULL, so you might want to care about this, too. For instance: E…
Error parsing query: [ Token line number = 1,Token line offset = 27,Token in error = BY ]
I’m trying to pass a SQL command to delete data which has a property BY ( unique nvarchar), but I get this parsing error every time. Error parsing query: [ Token line number = 1,Token line offset = 27,Token in error = BY ] I have also tried to do the same command to a different property called Category …
MySQL IN() Operator not working
How to use IN() Operator not working it’s. Those table are example and look the same as the real database I have.I don’t have the permitting to add tables or change Those are the tables: When I use this query it return me only the student with id =1 because “id IN (students)” return 1 …
Aggregate functions across multiple columns in postgres
I have a postgresql table with multiple fields containing integers (a1,a2,a3 etc). I want to run aggregate functions(mean, standard deviation etc) across more than one of the columns at once. (Some of them may have a reasonable number of nulls, so I don’t want to just generate column averages and then a…
How do I use a subquery to show a column that has never been assigned to a different table?
I’m trying to Write a SELECT statement that returns the category_name column from the Categories table and returns one row for each category that has never been assigned to a product in the Products table. there are four categories in the categories table and only three have been used in the products ta…
Printing integer variable and string on same line in SQL
Ok so I have searched for an answer to this on Technet, to no avail. I just want to print an integer variable concatenated with two String variables. This is my code, that doesn’t run: It seems like such a basic feature, I couldn’t imagine that it is not possible in T-SQL. But if it isn’t po…
Select a value from table with different criteria SQL
TABLE player idPlayer | name | 1 | name1 | 2 | name2 | 3 | name3 | 4 | name4 | Table matches idMatch | idPlayer1 | idPlayer2 | date | 1 | 1 | 2 …