I have a table that contains 4 columns and in the 5th column I want to store the count of how many non-null columns there are out of the previous 4. For example: Where X is any value: Answer
Tag: tsql
Test for Upper Case – T-Sql
All, How can I check if a specified varchar character or entire string is upper case in T-Sql? Ideally I’d like to write a function to test if a character is upper case, then I can later apply that to a generic varchar. It should return false for non alphabetic characters. I am only interested in english language characters. I
How to execute SQL statements saved in a table with T-SQL
Is it possible to execute a SQL statement Stored in a Table, with T-SQL? The statements that are stored in the table are ad-hoc statements which could be SELECT TOP 100 * FROM ATable to more complex statements: I want to execute the @Query Variable that I declared from T-SQL. Is this possible? (I am running a MSSQL 2005 enviroment)
Sql server – recursive delete
I’m trying to delete user’s data and all it’s related data that is located in different tables. All the tables have Foreign Keys but without cascade delete. I investigated some options: Enable cascade delete on all FK, delete and remove the cascade delete. Delete from bottom UP, loop up for all the leaves delete and repeat this operation till Root.
Use Aggregate Function in UNION ALL result set
How can I use aggregate Functions in UNION ALL Resultset FOR EXAMPLE Result Set Would Be When I tried to get MAX(A) it returns 3. I want 6. When I tried to get MAX(B) it returns 4. I want 7. Other than Max(), Can I get another aggregate function which user defined? For example: (SELECT TOP 1 A WHERE B=5)
Multiple OUTPUT clauses in MERGE/INSERT/DELETE SQL commands?
I have a T-SQL script that implements some synchronization logic using OUTPUT clause in MERGEs and INSERTs. Now I am adding a logging layer over it and I would like to add a second OUTPUT clause to …
SQL “between” not inclusive
I have a query like this: But this gives no results even though there is data on the 1st. created_at looks like 2013-05-01 22:25:19, I suspect it has to do with the time? How could this be resolved? It works just fine if I do larger date ranges, but it should (inclusive) work with a single date too. Answer It
SQL SERVER: Check if variable is null and then assign statement for Where Clause
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 off of a
SQL Server – Create a copy of a database table and place it in the same database?
I have a table ABC in a database DB. I want to create copies of ABC with names ABC_1, ABC_2, ABC_3 in the same DB. How can I do that using either Management Studio (preferably) or SQL queries ? This is for SQL Server 2008 R2. Answer Use SELECT … INTO: This will create a new table ABC_1 that has
How to convert a loop in SQL to Set-based logic
I have spent a good portion of today and yesterday attempting to decide whether to utilize a loop or cursor in SQL or to figure out how to use set based logic to solve the problem. I am not new to set logic, but this problem seems to be particularly complex. The Problem The idea is that if I have