with mycte as
(
select cast('12:00 AM' as time) starttime
union all
select dateadd(s,1,starttime)
from mycte
where dateadd(s,1,starttime) < cast('11:59 PM' as time)
)
select starttime AS Time,datepart(hh,starttime) as Hour,datepart(mi,starttime) as Minutes,datepart(s,starttime) as Seconds
from mycte
OPTION
(MAXRECURSION 0)
Monday, August 15, 2011
Thursday, August 11, 2011
How to Limit the No of Records Per Page in SSRS
e.g. (Columns)
DepartmentName, EmployeeId, Employee Name, Designation, Reporting Manager
We want to show 4 DepartmentName per Page so here is the solution:
Need to use DepartmentName in group (Add a group as parent group, Group by DepartmentName) .
Once it is done then go again in the group properties and change the expression like Change Group on value with following mentioned expression and use group by: (Change in Exp with)
=Ceiling((RowNumber(Nothing)) / 4)
OR
=Floor((RowNumber(Nothing) - 1) / 4)
NOTE: Now you have to add DepartmentName as normal column to show values in the report so set the width of group column to 0 and change the text color, background color (if set) to none (white) and font size to 1, remove borders so that this column should not apper in the report (Please do not hide it otherwiswe values will not appear in the report).
DepartmentName, EmployeeId, Employee Name, Designation, Reporting Manager
We want to show 4 DepartmentName per Page so here is the solution:
Need to use DepartmentName in group (Add a group as parent group, Group by DepartmentName) .
Once it is done then go again in the group properties and change the expression like Change Group on value with following mentioned expression and use group by: (Change in Exp with)
=Ceiling((RowNumber(Nothing)) / 4)
OR
=Floor((RowNumber(Nothing) - 1) / 4)
NOTE: Now you have to add DepartmentName as normal column to show values in the report so set the width of group column to 0 and change the text color, background color (if set) to none (white) and font size to 1, remove borders so that this column should not apper in the report (Please do not hide it otherwiswe values will not appear in the report).
How to reset Identity value in SQL Server Table
DBCC CHECKIDENT ('your table name',RESEED,new_seed_value)
Wednesday, August 3, 2011
Tables or SP structure modified (IF)
-- tables Structure modified today
SELECT [name],create_date,modify_date
FROM sys.objects
WHERE modify_date>DATEADD(day,-1,GETDATE())
AND type='U'
-- Stored procedures modified today
SELECT [name],create_date,modify_date
FROM sys.objects
WHERE modify_date>DATEADD(day,-1,GETDATE())
AND type='P'
-- Tables structure modified in last 7 days
SELECT [name],create_date,modify_date
FROM sys.objects
WHERE modify_date>DATEADD(day,-7,GETDATE())
AND type='U'
SELECT [name],create_date,modify_date
FROM sys.objects
WHERE modify_date>DATEADD(day,-1,GETDATE())
AND type='U'
-- Stored procedures modified today
SELECT [name],create_date,modify_date
FROM sys.objects
WHERE modify_date>DATEADD(day,-1,GETDATE())
AND type='P'
-- Tables structure modified in last 7 days
SELECT [name],create_date,modify_date
FROM sys.objects
WHERE modify_date>DATEADD(day,-7,GETDATE())
AND type='U'
How to findout which table modified Today
--This query will show the tables and their insert/update records for current date but only for those tables who have ModifiedDate Column in the table
CREATE TABLE #TEMPRECORD
(
ID INT IDENTITY,
TABLENAME VARCHAR(200)
)
DECLARE @I INT =1,
@TOTAL INT =0,
@SQL VARCHAR(500),
@TNAME VARCHAR(200),
@COLUMNNAME VARCHAR(100)
SELECT @COLUMNNAME = 'MODIFIEDDATE'
INSERT #TEMPRECORD (TABLENAME)
SELECT DISTINCT O.NAME FROM SYS.OBJECTS O INNER JOIN SYS.COLUMNS C
ON O.OBJECT_ID = C.OBJECT_ID
WHERE O.TYPE ='U'
AND C.NAME = @COLUMNNAME
SELECT @TOTAL = COUNT(*) FROM #TEMPRECORD
WHILE @I <= @TOTAL
BEGIN
SELECT @TNAME = NAME FROM SYS.OBJECTS WHERE NAME = (SELECT TABLENAME FROM #TEMPRECORD WHERE ID =@I )
SELECT @SQL ='SELECT * FROM '+@TNAME +' WHERE CONVERT(VARCHAR(12),'+@COLUMNNAME+',101) = CONVERT(VARCHAR(12),GETDATE(),101)'
SELECT @TNAME AS [TABLE NAME]
EXEC (@SQL)
SET @I=@I+1
END
GO
DROP TABLE #TEMPRECORD
GO
CREATE TABLE #TEMPRECORD
(
ID INT IDENTITY,
TABLENAME VARCHAR(200)
)
DECLARE @I INT =1,
@TOTAL INT =0,
@SQL VARCHAR(500),
@TNAME VARCHAR(200),
@COLUMNNAME VARCHAR(100)
SELECT @COLUMNNAME = 'MODIFIEDDATE'
INSERT #TEMPRECORD (TABLENAME)
SELECT DISTINCT O.NAME FROM SYS.OBJECTS O INNER JOIN SYS.COLUMNS C
ON O.OBJECT_ID = C.OBJECT_ID
WHERE O.TYPE ='U'
AND C.NAME = @COLUMNNAME
SELECT @TOTAL = COUNT(*) FROM #TEMPRECORD
WHILE @I <= @TOTAL
BEGIN
SELECT @TNAME = NAME FROM SYS.OBJECTS WHERE NAME = (SELECT TABLENAME FROM #TEMPRECORD WHERE ID =@I )
SELECT @SQL ='SELECT * FROM '+@TNAME +' WHERE CONVERT(VARCHAR(12),'+@COLUMNNAME+',101) = CONVERT(VARCHAR(12),GETDATE(),101)'
SELECT @TNAME AS [TABLE NAME]
EXEC (@SQL)
SET @I=@I+1
END
GO
DROP TABLE #TEMPRECORD
GO
Subscribe to:
Posts (Atom)