Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 30th, 2007, 12:34 PM
Authorized User
 
Join Date: Mar 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to miamikk
Default Nested Loops in SQL Query values from table/set

Nested Loops in SQL Query with values fetched from table/set

I am a newbie SQL programmer. I need to know the syntax/example for using nested loops with condition values fetched from a table/group of fixed values etc.

The SQL Query needs creates an XML file for each combination of 3 parameters District, Month, RepType.

District values need be fetched from a table “district” and column “dist_code”. The dist_code is of type “tinyint” and its value is between 1-70.

Month values can be either fetched from a table or a fixed set. Its value is from 1-12. The table is “month” and the column name is “stat_month”. The stat_month is of type char(2).

RepType values are 1-11 need to be fetched from a fixed set.


The SQL query is below (with hard coded parameter values)
*************Begin Code************
USE test
GO

Declare @TblName1 varchar(10)
Declare @District varchar(6)
Declare @Month varchar(3)
Declare @RepType varchar(2)

SET @TblName1 = '2006exp'
SET @District = 21
SET @Month = 6
SET @RepType = 2

Declare @fName varchar(50)
SET @fName = 'C:\XMLDump\'+@TblName1+'-'+@District+'-'+@Month+'-'+@Reptype+'.xml'

SET @TblName1 = '['+@TblName1+']'

Declare @SQuery nvarchar(3000)

Set @SQuery = 'bcp "EXEC test..free_CustomsDistrict_HS4_TEST '+@TblName1+', '+@District+', '+@Month+', '+@RepType+'" QueryOut "' + @fName + '" -c -T -r -t'

Exec master..xp_cmdshell @SQuery
************End Code*************
When I execute this query, it creates a file “2006exp-21-6-2.xml”.

The need the query to create 46x12x11 = 6072 files for all the combinations of 3 parameters.


 
Old August 31st, 2007, 12:35 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Asked and fully answered here
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=88696





Similar Threads
Thread Thread Starter Forum Replies Last Post
break for-each loops, or limit amount of loops warhero XSLT 2 July 4th, 2007 02:18 AM
weird program flow with nested loops zayasv Intro Programming 2 November 17th, 2005 06:19 AM
problem with nested loops ptaylor2005 Beginning PHP 4 April 27th, 2005 07:05 PM
Set query up to automatically run in SQL server ALLA SQL Server 2000 3 October 21st, 2004 04:24 PM
xml result set truncated in sql query analyzer xologist SQL Server 2000 2 March 22nd, 2004 05:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.