What is best way to check if value is null or empty string in Postgres sql statements? Value can be long expression so it is preferable that it is written only once in check. Currently I’m using: But it looks a bit ugly. stringexpression may be char(n) column or expression containing char(n) columns wit…
Set column to a concatenated value from another table
I have 2 tables in SQL Server 2008: Address: nameid | e-mail ————— 1 | xyz@abc.com 2 | fgh@asdf.com 3 | 123@doremi.com Member: nameid | memberid ————— 1 | …
How to fill missing dates and values in partitioned data?
How to fill missing dates and values in partitioned data? I’m having a lot of trouble Googling this as most of the posts seem to feature Oracle databases, and I’m working with Microsoft SQL Server. I have the following hypothetical table: I want to fill in the dates in between the gaps and copy ov…
Query JSON inside SQL Server 2012 column
I have a column inside my SQL Server 2012 table which contains following Json data. Now I want to use this column data in my query like Is there a way to query JSON data in SQL Server 2012? Answer Honestly, this is a terrible architecture for storing the data, and can result in some serious performance issues…
MySQL #1064 Error DATETIME
I’m making a web based mail system, and I have to create a table with this code: MySQL says: #1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ”messages'( ‘ID’ INT(250) NOT NULL AUTO_INCRE…
How to create copy of database using backup and restore
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…
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 …