I am trying to achieve something like the below in WHERE clause in sql. I tried the following: which is wrong. Can anyone help in framing the exact statement. Thanks! Answer Isnull() syntax is built in for this kind of thing. For your example keep in mind you can change scope to be yet another where predicate…
Null or empty check for a string variable
I want to know whether the above piece of code works in checking if the variable is null or empty. Answer Yes, that code does exactly that. You can also use: Edit: With the added information that @value is an int value, you need instead: An int value can never contain the value ”.
Based on date range how to get unique, new, and repeat results?
I have a database table with datetime field and also contains user id (foreign key). I need to get the activity of unique, new, and repeat users. If a user does some activity, a database row is …
SQLite, insert variable in my table (c# console app)
I was wondering if it is possible to insert a variable in my SQLite table (like the TheName in the example code) , and if it is how are you able to do it ? Answer You need parameterized queries:
Optimize BETWEEN date statement
I need help optimizing a Postgres query which uses the BETWEEN clause with a timestamp field. I have 2 tables: containing about 3394 rows containing about 4000000 rows There are btree indexes on both PKs id_one and id_two, on the FK id_one and cut_time. I want to perform a query like: This query retrieves abo…
Using SQL Merge or UPDATE / INSERT
I have a table (Customer_Master_File) that needs to updated from flat files dumped into a folder. I have an SSIS package that runs to pick up the flat files and imports them into a temp table (temp_Customer_Master_File) What I have been unable to do is this: for each record in the temp table, if the Customer_…
“Unknown column in ‘field list'”, but column does exist
DROP TABLE IF EXISTS `transactions`; CREATE TABLE `transactions` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `purchase_date` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB …
Joining multiple tables in SQL
Can sombody Explains me about joins? Inner join selects common data based on where condition. Left outer join selects all data from left irrespective of common but takes common data from right table and vice versa for Right outer. I know the basics but question stays when it comes to join for than 5, 8, 10 ta…
Is SELECT or INSERT in a function prone to race conditions?
I wrote a function to create posts for a simple blogging engine: CREATE FUNCTION CreatePost(VARCHAR, TEXT, VARCHAR[]) RETURNS INTEGER AS $$ DECLARE InsertedPostId INTEGER; TagName …
Convert Rows to columns using ‘Pivot’ in SQL Server
I have read the stuff on MS pivot tables and I am still having problems getting this correct. I have a temp table that is being created, we will say that column 1 is a Store number, and column 2 is a week number and lastly column 3 is a total of some type. Also the Week numbers are dynamic,