I have a column in a table which might contain null or empty values. How do I check if a column is empty or null in the rows present in a table? (e.g. null or ” or ‘ ‘ or ‘ ‘ and …)
Generate sequence in SQL Server, poor performance with cross apply
I obtained the following code from the web many years ago and it has served my very well. It is simply a function that generates a sequence of numbers from 1 to whatever you pass in. Basically it’s a way of doing a for loop in a SQL statement. This generally works very well and is fast but I have
Does using “LIMIT 1” speed up a query on a primary key?
If I have a primary key of say id and I do a simple query for the key such as, Will it find one row and then stop looking as it is a primary key, or would it be better to tell mysql to limit its select by using LIMIT 1? For instance: Answer Does using “LIMIT 1” speed up
Join two tables where table A has a date value and needs to find the next date in B below the date in A
I got this table “A”: and this table “B”: Now I am looking for a way to JOIN those two tables having the “value” column in “B” mapped to the dates in “A”. The tricky part for me here is that table “B” only stores the change date and the new value. Now when I need this value in table
Dynamically name indexes in SQL Server 2005?
As most people who work with Sql Server know, you can declare a temporary table like so: …this will create a primary key and a default constraint on this temporary table; the names for these objects will be unique, dynamically created by Sql Server. Is it possible to create a dynamically named index for the table after it’s been created?
JPA @ManyToMany join table indexing
Hibernate allows adding indexes on @ManyToOne mappings by the use of @org.hibernate.annotations.Index. Is there a way to specify index for the join table in a @ManyToMany relation? If Entity A and …
Referring to a Column Alias in a WHERE Clause
I get “invalid column name daysdiff”. Maxlogtm is a datetime field. It’s the little stuff that drives me crazy. Answer Normally you can’t refer to field aliases in the WHERE clause. (Think of it as the entire SELECT including aliases, is applied after the WHERE clause.) But, as mentioned in other answers, you can force SQL to treat SELECT to
Using SELECT for simple BOOLEAN evaluation
I want to test some evaluations without working on any table. For example, you can write I want to achieve something like this: I know that most engines don’t have the concept of a boolean data type, but I don’t know how their internal work (even if I guess everything <> 0 is true, like in C). Anyway, the format
Set variable value to array of strings
I want to set a variable as a string of values. E.g. declare @FirstName char(100) select @FirstName = ‘John’,’Sarah’,’George’ SELECT * FROM Accounts WHERE FirstName in (@FirstName) I’m getting a …
SQL Query to update a column based on the values of other columns in the same table
Ok this is difficult to phrase, so here goes… I am using MS SQL Server 2008 R2. I have a temp table that lets say has two already populated columns. There is a third empty column I want to populate based on the value of the first two columns. What I want to do is create a guid (using NEWUID())