Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

SQL Blog by Rahul Sahay

I have a total experience of 6 years primarily in databases (T-SQL and Performance Tuning). I have worked on different versions starting with SQL Server 2000 to SQL Server 2008 R2 for companies like Accenture and Airtel. I have completed Microsoft certification in MCTS (SQL SERVER). I did my MCA (Masters Of Computer Application) degree from Bangalore and have a BCA (Bachelor Of Computer Applications) from Indore.

Creating Dimension Table ==> Time (Example)


Script for Dimension table for Time.

Here Date_ID is the primary key which can be used as the foreign key in the fact tables.

CREATE TABLE [dbo].[DATE_DIM]

                (

                 [DATE_ID] [bigint] IDENTITY(1, 1)

                                    NOT NULL

                ,[SQL_DATE] [datetime] NOT NULL

               …

Read more

0 comments, 373 reads

Posted in SQL Blog by Rahul Sahay on 22 April 2013

Total Number Of Records In each Table

Quite often in our day today activity we need to check the count of records in each table of the database. So instead of firing count(*) against all the table, we can use the DMV's ie inbuild system procedures or functions to get the desired result.

Code :


select …

Read more

0 comments, 339 reads

Posted in SQL Blog by Rahul Sahay on 3 April 2013

SQL BLOG: First Occurrence Of Character In a String



Scenario:

 We need to find the first occurrence of character ie non numeric data in the string without using the built in function.
Example: String 577a     
First occurrence of character : 4

Approach:

i)                    Here I haven’t used any built in functions. First we need to find…

Read more

4 comments, 957 reads

Posted in SQL Blog by Rahul Sahay on 1 March 2013

SQL BLOG: Using Triggers for creating history tables in SQL Server



Case Study:
1)       We  need to track the employee table in terms of new records inserted along with the datetime stamp

2)      In case any updation, we need to track the same with only the column name that is updated. Rest all columns should be null. All tracking…

Read more

1 comments, 667 reads

Posted in SQL Blog by Rahul Sahay on 28 February 2013

SQL BLOG: Calculating total number of days from 1st Jan without using DATEDIFF function

Below script will calculate total number of days based on the input from user from 1st Jan. Though we have a built in function DATEDIFF from which we can calculate this easily. But in the below script, i have tried calculating the days without this built in function.

I have…

Read more

0 comments, 340 reads

Posted in SQL Blog by Rahul Sahay on 25 February 2013

SQL BLOG: Calculating number of week along the days completed in that week for a given input date

Below code will display the week started along with the number of days completed in that week. For deriving this have used the modulo function.

Week-4 for this code starts from 22nd till the last day of the month, that's why week-4 remaining days are calculated by dividing with 21…

Read more

0 comments, 245 reads

Posted in SQL Blog by Rahul Sahay on 24 February 2013

SQL BLOG: Playing with Date Time

Below code returns remaining days in the month based on the input date. We can have this inside a function also which will return the integer value.


/* code starts here */

/* calculate remaining days in the month from the given input */
declare @tdate datetime
set @tdate =…

Read more

2 comments, 155 reads

Posted in SQL Blog by Rahul Sahay on 24 February 2013