Posts

Showing posts from September, 2017

Get Time Of Day c#

public static string GetTimeOfDay (DateTime dateTime) { if (dateTime.Hour >= 0 && dateTime.Hour < 6 ) { return "Night" ; } if (dateTime.Hour >= 6 && dateTime.Hour < 12 ) { return "Morning" ; } if (dateTime.Hour >= 12 && dateTime.Hour < 18 ) { return "Noon" ; } return "Evening" ; }

Drop all the tables, stored procedures, triggers, constraints and all the dependencies in one sql statement

PRINT 'Dropping whole database' GO ------------------------------------------ -- Drop constraints ------------------------------------------ DECLARE @ Sql NVARCHAR ( 500 ) DECLARE @ Cursor CURSOR SET @ Cursor = CURSOR FAST_FORWARD FOR SELECT DISTINCT sql = 'ALTER TABLE [' + tc2 . CONSTRAINT_SCHEMA + '].[' + tc2 . TABLE_NAME + '] DROP [' + rc1 . CONSTRAINT_NAME + ']' FROM INFORMATION_SCHEMA . REFERENTIAL_CONSTRAINTS rc1 LEFT JOIN INFORMATION_SCHEMA . TABLE_CONSTRAINTS tc2 ON tc2 . CONSTRAINT_NAME = rc1 . CONSTRAINT_NAME OPEN @ Cursor FETCH NEXT FROM @ Cursor INTO @ Sql WHILE (@@ FETCH_STATUS = 0 ) BEGIN PRINT @ Sql Exec (@ Sql ) FETCH NEXT FROM @ Cursor INTO @ Sql END CLOSE @ Cursor DEALLOCATE @ Cursor GO ------------------------------------------ -- Drop views ------------------------------------------ DECLARE @ sql VARCHAR ( MAX ) = '' , @ crlf VARCHAR ( 2 ) = ...