Re: Adding lines to a table base on a Quanitity

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: David Portas (REMOVE_BEFORE_REPLYING_dportas_at_acm.org)
Date: 03/21/04


Date: Sun, 21 Mar 2004 22:41:06 -0000

Sorry, I got the BETWEEN expressions swapped around. This should do it:

INSERT INTO Something (member_no, number, ....)
    SELECT T.member_no, N.number, ....
        FROM Tickets AS T
        JOIN Numbers AS N
            ON N.number BETWEEN 1 AND T.ticket_qty

> need it to loop through each member number.

I suspect that's not what you *need*. SQL is primarily a declarative
language, not a procedural one. The best starting point when writing a query
is to define the result you require (the output of the query) rather than
how to get it (e.g. a loop).

Hope this helps.

-- 
David Portas
SQL Server MVP
--


Relevant Pages

  • Re: SQL 2000, SP3a "TOP 100%"
    ... The best place to use ORDER BY is when you query the view. ... David Portas ... SQL Server MVP ... Prev by Date: ...
    (microsoft.public.sqlserver)
  • Re: Whats wrong ?
    ... Your query is syntactically valid so the problem is in your ... David Portas ... SQL Server MVP ...
    (microsoft.public.sqlserver)
  • setting in server sql2000
    ... Thank's 4 ur attention David Portas. ... BEFORE INSTALLED service pack 2/3, this query result: ... > SQL Server MVP ...
    (microsoft.public.sqlserver.server)
  • Re: sp3 in sql 2000
    ... Thank's 4 ur attention David Portas. ... BEFORE INSTALLED service pack 2/3, this query result: ... > SQL Server MVP ...
    (microsoft.public.sqlserver.server)
  • Re: FTS Performance in SQL 2005
    ... Can you post you query plans and the output of statistics IO ... SQL Server MVP ... Because i've set the MAX sql-server memory to 3.5 GB instead of 4.0 GB ... cost relative to the whole batch, ...
    (microsoft.public.sqlserver.fulltext)