I have a string variable that denotes a time: I need to check if the current time getdate() is after or before @time. How can I do this in SQL? Answer This should do it: SQL 2008+ Earlier:
Tag: sql-server-2005
How to convert a varchar column to bit column in SQL SERVER
Flag1 is a varchar column with values “true” and “false”. I need to convert this into bit column. When I try to do this: Convert(Bit,Flag1) it shows an error Msg 245, Level 16, State 1, Line 2 …
Add/remove columns of a table – code maintenance / optimisation
What is the best way to maintain code of a big project? Let’s say you have 1000 stored procedures, and you have to add a new column to a table (or remove) There might be 1-2 or 30 stored procedures, that might be affected. Just a single “search” for the tablename might not be good enough, let’s say you only
Check users in a security group in SQL Server
In the Security/Users folder in my database, I have a bunch of security groups, include “MyApplication Users”. I need to check if I am (or another user is) in this group, but I have no idea how to query for it or where I could see this information. I tried looking in the properties, but couldn’t find anything. Any ideas?
Create trigger to insert a column value into other column of same table SQL Server 2005
How to create trigger to insert a value in a column same as value of another column of same table of a newly inserted row in the table. Suppose I have table like below I want columnB value to be inserted into ColumnA as soon as row gets inserted into table or columnB value gets updated . But it should
Is the LIKE operator case-sensitive with SQL Server?
In the documentation about the LIKE operator, nothing is told about the case-sensitivity of it. Is it? How to enable/disable it? I am querying varchar(n) columns, on an Microsoft SQL Server 2005 installation, if that matters. Answer It is not the operator that is case sensitive, it is the column itself. When a SQL Server installation is performed a default
IIF(…) not a recognized built-in function
I’m trying to use this in Microsoft SQL Server 2008 R2: But I get an error: IIF(…) is not a recognized built-in function name Is IIF() only compatible with a later version? Is there an alternate function I can use? Answer IIF comes from SQL 2012. Before then, you can use CASE:
How to use regular expression in T-SQL?
For example: where strword match with {%{J{GC * GC}J} or strword={%{J{GC * GC}J}
How to sum Accounts
I have 3 tables: DimAccounts, DimTime and FactBudget. DimAccounts example: DimTime example: FactBudget example: In FactBudget are many Accounts just with type B. I need to calculate Debit and Credit Sums where Account type is S (Sum). Columns AccountFrom and AccountTo shows B Type Accounts from where to begin summing (AccountFrom ) and where end (AccountTo). I have made solution
Remove duplicate data in ‘date-ranged’ rows
I have a table like the following. The date range is used to know for what time period the rest of the Attributes were valid, the problem i have is that there are several consecutive time ranges where the Attributes ramain the same, what I would like is to obtain the same data but without the duplicate rows. From the