Advanced Querying

SQLServerCentral Article

Beauty is in the Eye of the Beholder

  • Article

Is dynamic SQL good or bad? We've had lots of arguments over the years in the forums and articles on both sides of the coin, though with most of the opinions being that dynamic SQL is bad. Stephen Hirsch brings us his own view that beauty is in the eye of the beholder.

You rated this post out of 5. Change rating

2006-09-19

5,800 reads

SQLServerCentral Article

The Joy of Numbers

  • Article

Numbers are fascinating concepts in all types of mathematics, but they can be very helpful as well in your SQL Server queries. Guru Michael Coles brings us a look at how a numbers table can you and includes a bunch of code for both SQL Server 2000 and SQL Server 2005.

5 (1)

You rated this post out of 5. Change rating

2006-08-14

18,169 reads

Technical Article

Using correlated sub-queries in SQL Server

  • Article

A sub-query is a SQL Server statement embedded inside of another SQL Server statement. The database engine treats a sub-query as a virtual table for the execution of the query. A sub-query can be used as a table in a join statement, as a single value in a select statement, in the where clause of a SQL Server query, in the having clause of a SQL Server query, or incorporated in data manipulation statements.

2006-08-07

4,276 reads

Blogs

SQL Server Performance – What IT Leaders Need to Know

By

IT leaders have a lot on their plates! Budgets, staffing, security, uptime, and keeping...

FREE Window Functions Course (This Month Only!)

By

Want to really level up your SQL game? I mean, go from good to great? This March...

Tally Table Alternatives: #SQLNewBlogger

By

We published an article recently at SQL Server Central on Tally Tables in Fabric...

Read the latest Blogs

Forums

Dynamic T-SQL Script Parameterization Using Python

By omu

Comments posted to this topic are about the item Dynamic T-SQL Script Parameterization Using...

Multiple Sequences

By Steve Jones - SSC Editor

Comments posted to this topic are about the item Multiple Sequences

Using SQL Server Stored Procedures with the Django ORM

By omu

Comments posted to this topic are about the item Using SQL Server Stored Procedures...

Visit the forum

Question of the Day

Multiple Sequences

In SQL Server 2022, I run this code:

CREATE SEQUENCE myseqtest START WITH 1 INCREMENT BY 1;
GO
CREATE TABLE NewMonthSales
  (SaleID    INT
  , SecondID int
 , saleyear  INT
 , salemonth TINYINT
 , currSales NUMERIC(10, 2));
GO
INSERT dbo.NewMonthSales
  (SaleID, SecondID, saleyear, salemonth, currSales)
SELECT
  NEXT VALUE FOR myseqtest
, NEXT VALUE FOR myseqtest
, ms.saleyear
, ms.salemonth
, ms.currMonthSales
FROM dbo.MonthSales AS ms;
GO
SELECT * FROM dbo.NewMonthSales AS nms

Assume the dbo.MonthSales table exists. If I run this, what happens?

See possible answers