T-SQL

Technical Article

Bitmap an Integer Value

  • Script

Do you hate using bitwise operands?  I do, a lot.  I wrote the following function to try to minimize the need for using them.  When testing 'status' variables in the 'sysobjects' table, for example, I decided there just had to be an easier way to see if bit 31 is set than asking if STATUS […]

You rated this post out of 5. Change rating

2003-03-07

668 reads

Technical Article

A Simple way to find the line of script.

  • Script

You can use this procedure to find any word or sentance, which u used in procedures, views, triggers and function. This procedure is basically a modified form of system procedure "sp_helptext". Now its upto you to use that and modified that. To execute the procedure, first create it in your Database and then execute it […]

You rated this post out of 5. Change rating

2003-02-24

143 reads

Technical Article

Recreate dependencies in database

  • Script

This procedure refresh all views of current database in good order to recreate correct dependencies lost after updating views.This procedure just call sp_refreshview and uses temporary tableExecution of this procedure prevent errors in DTS Import/Export wyzard : Copy objects and data between SQL Server databasesexec refresh_all_views_in_order -- in current database and all dependencies are ok […]

You rated this post out of 5. Change rating

2003-02-13

689 reads

Technical Article

MetaData_TableDependenceOrder

  • Script

MetaData_TableDependenceOrder Lists User tables in foreign key dependence order.I use this to determine data load order without having to disable foreign key constraints accepts a database name (required) and an optional comma delimited list of tables to filter the dependency list with. If tablelist is not passed, it returns all tables with a load ranking […]

You rated this post out of 5. Change rating

2003-02-12

144 reads

SQLServerCentral Article

Using Exotic Joins in SQL - Part 2

  • Article

In the previous article, you saw how the BETWEEN operator could be used in joins to solve problems dealing with range-based data. In this article, Chris Cubley will show you how to take joins even further by using multiple criteria in joins as well as using the greater than, less than, and not equals operators in joins.

You rated this post out of 5. Change rating

2003-02-05

13,739 reads

Technical Article

Delete record efficiently. (sp_CheckAndDelete )

  • Script

The sp_CheckAndDelete stored procedure specially created for handling process of data deleting efficiently in MS SQL Server 2000 tables, as it is too difficult to handle this process when dependants exist for record to be deleted. When the deleting process is done with sp_CheckAndDelete stored procedure, you will be informed the status of the process […]

You rated this post out of 5. Change rating

2003-01-30

185 reads

SQLServerCentral Article

Using Exotic Joins in SQL Part 1

  • Article

When most developers think of joins, they think of a.SomethingID = b.SomethingID. This type of join, the equijoin, is vitally important to SQL programming; however, it only scratches the surface of the power of the SQL join. This is the first in a series of articles that will look at several different types of exotic joins in SQL. This article will focus on using the BETWEEN operator in joins when dealing with range-based data.

5 (2)

You rated this post out of 5. Change rating

2017-08-23 (first published: )

37,963 reads

Blogs

Free webinar – Tackling the Gaps and Islands Problem with T-SQL Window Functions

By

I’m hosting a free webinar at MSSQLTips.com at the 19th of December 2024, 6PM...

Counting Groups with Window Functions: #SQLNewBlogger

By

I looked at row_number() in a previous post. Now I want to build on...

Read the latest Blogs

Forums

Find rows with very close time stamps

By daytonbrown2

Given the following table and query, this will return any records(based on message_id) that...

How to merge two tables with unlike fields

By landonh

How to merge two tables with unlike fields. I have two table with one...

Visual Studio 22 / SSIS Project / (Project) Connection problem

By WilburSmith

Hello, First of all, I find it odd/annoying that I can't exclude a Project...

Visit the forum

Question of the Day

The LAGging NULL

I have this data in a SQL Server 2022 table:

player         yearid team HR
Alex Rodriguez 2012   NYY  18
Alex Rodriguez 2013   NYY  7
Alex Rodriguez 2014   NYY  NULL
Alex Rodriguez 2015   NYY  12
Alex Rodriguez 2016   NYY  9
If I run this code, what are the results returned in the hrgrowth column?
SELECT
  player
, yearid
, hr
, hr - LAG (hr, 1, 0) IGNORE NULLS OVER (ORDER BY yearid) AS hrgrowth
FROM dbo.playerstats;

See possible answers