Hot answers tagged sql-server-2008
Use the DATENAME() function and specify the datepart as weekday. select ID, Name, Salary, Date from dbo.yourTable where datename(weekday, Date) in ('Saturday', 'Sunday'); As Aaron pointed out, this relies on the language being set to English. Likewise, you could use the DATEPART() function with weekday and test for Saturday and Sunday values.
Not 100% reliable (could yield false positives, or miss things due to dynamic SQL etc): SELECT s.name, p.name, m.definition FROM sys.schemas AS s INNER JOIN sys.procedures AS p ON s.[schema_id] = p.[schema_id] INNER JOIN sys.sql_modules AS m ON p.[object_id] = m.[object_id] WHERE LOWER(m.definition) LIKE N'%update%tablename%'; You can't ...
You can use a filtered unique undex to apply a uniqueness constraint to a filtered set of data. For example this: http://sqlmag.com/blog/whats-good-use-unique-filtered-index For example you could exclude your non unique rows from the index and make it unique But you really need to fix your data or it's going to cause you problems in future.
If you are able to delete duplicated records or update them in order to make it unique you should to it. Then, create your unique constrain. If you are not allowed to do this, and you want to add an unique constrain for any insert or update operation from now, you can create: stored procedure that is inserting/updating records in the table but first check ...
Funny answer to this one for me. One of the subscribers was still attempting to connect to this publication. Once I found it, I deleted it and all was good in the hood.
Everyone has been putting solutions that depend on setting either language or datefirst. However, assuming that you're looking for dates only after 1900-01-01, (which was a Monday) SELECT ID ,Name ,Salary ,Date FROM <Table_Name> WHERE DateDiff(dd, 0, Date) % 7 in (5,6) Regardless of any settings, since 0 (or 1900-01-01) is a ...
Try this: CREATE TABLE #TempTable (NAME NVARCHAR(MAX), CODE NVARCHAR(MAX)); DECLARE C CURSOR FOR SELECT DISTINCT name FROM sys.procedures; DECLARE @spname NVARCHAR(MAX), @sptext nvarchar(MAX); OPEN C; FETCH NEXT FROM C INTO @spname WHILE @@Fetch_status = 0 BEGIN SET @sptext = (select definition from sys.sql_modules where ...
Only top voted, non community-wiki answers of a minimum length are eligible