Scripts

Technical Article

Get the Value of a BitMask

This function will take a 64 bitmask string and return the value of bitmask. If you need 128, 256, etc simply change the length of the parameter, being careful to remember you may need to change the return type of int to BigInt if you get too long.

You rated this post out of 5. Change rating

2005-01-04 (first published: )

239 reads

Technical Article

Generating sequential numbers - the fast way

It is often necessary to generate a table with sequential numbers, up to a specified upper limit N. For small N, a simple INSERT in a WHILE loop will do. But, for large N, that solution becomes too slow. This script presents a different approach. It generates sequential numbers from the binary representation of N, […]

4.5 (2)

You rated this post out of 5. Change rating

2004-12-30 (first published: )

621 reads

Technical Article

Number of Weekdays between two dates - Set Based

Inspired by a post here at SQLServerCentral, I wrote this function to calculate the number of days between two dates that are weekdays. In order to achieve this I used a common SQL table that contains a sequence of number for 1 to X. This was used as an input to the datediff function, and […]

You rated this post out of 5. Change rating

2004-12-24 (first published: )

305 reads

Technical Article

Retrieving all indexes of the Database.

The Script outputs all the indexes in the Database.I have used the sp_helpIndex system stored procedure here to retrieve all the indexes available for the Table . This is extremely useful in identifying all the indexes in a database in a single query

5 (2)

You rated this post out of 5. Change rating

2004-12-22 (first published: )

326 reads

Technical Article

Update multiple rows (in a set) using a single SP

Here is another variation of processing multiple records with a single procedure call but allowing for set processing.The helper functions make use of the sequencetable pattern. These helper functions can be used to parse strings into records, so one gets a list, or simply return the nth field.There are two functions that will parse into […]

You rated this post out of 5. Change rating

2004-12-17 (first published: )

779 reads

Blogs

Advice I Like: Fear and Imagination

By

Fear is fueled by a lack of imagination. The antidote to fear is not...

Cloud Data Driven User Group 2025 – Slides & Scripts

By

The slidedeck and the SQL scripts for the session Indexing for Dummies can be...

Leading Through Change: Guiding Teams in Times of Uncertainty

By

Change is not a disruption in technology; it is the rhythm. New frameworks appear,...

Read the latest Blogs

Forums

Simple delete causes table scan on other tables with foreign key

By askcoffman

Why is sql doing a full scan VS seeking on the index? I've included...

Show/Hide number of rows in table

By marty.seed

We have a report that has multiple tables that list the top 15 performers...

Replication from IBMi DB2 to MS SQL

By homebrew01

We have a tool called DB Moto that reads journals (like t-logs) and replicates...

Visit the forum

Question of the Day

Checking Identities

The DBCC CHECKIDENT command is used when working with identity values. I have a table with 10 rows in it that looks like this:

TravelLogID CityID  StartDate   EndDate
1           1       2025-01-11  2025-01-16
2           2       2025-01-11  2025-01-16
3           3       2025-01-11  2025-01-16
4           4       2025-01-11  2025-01-16
5           5       2025-01-11  2025-01-16
6           6       2025-01-11  2025-01-16
7           7       2025-01-11  2025-01-16
8           8       2025-01-11  2025-01-16
9           9       2025-01-11  2025-01-16
10          10      2025-01-11  2025-01-16
The docs for DBCC CHECKIDENT say this if I run with only the table parameter: "If the current identity value for a table is less than the maximum identity value stored in the identity column, it is reset using the maximum value in the identity column. " I run this code:
DELETE dbo.TravelLog WHERE TravelLogID >= 9
GO
DBCC CHECKIDENT(TravelLog, RESEED)
GO
INSERT dbo.TravelLog
(
    CityID,
    StartDate,
    EndDate
)
VALUES
(4, '2025-09-14', '2025-09-17')
GO
What is the identity value for the new row inserted by the insert statement above?

See possible answers