473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Create XML in ASP.NET 2.0 then use for joined table in SQL Server 2005 Stored Procedure

Here's my problem:

I'm developing an ASP.NET 2.0 application that has a user select one or more
auto manufacturers from a listbox ("lstMakes"). Once they do this, another
listbox ("lstModels") should be filled with all matching models made by the
selected manufacturers. If lstMakes was not multi-select, I'd have no
problem. But in this case it has to be multi-select. The database is SQL
Server 2005 which does not accept arrays as parameters. I've been told that
I have to create an XML document that will act as a filtered Manufacturers
table that I can join to my Models table in my stored procedure. Problem is
I don't have the foggiest idea how to do this. I've seen some examples that
just leave me scratching my head so I was hoping someone could look at what
I'm trying to do and show me how to do this. Thanks!

Jun 11 '06 #1
2 989
Hi
Another way is to write an UDF that does split on your parameters
Take a look at Erland's example

CREATE PROCEDURE get_company_names_inline
@customers nvarchar(2000)
AS
SELECT C.CustomerID, C.CompanyName
FROM Northwind..Customers C
JOIN inline_split_me(@customers) s ON C.CustomerID = s.Value
go
---Usage
EXEC get_company_names_inline 'ALFKI,BONAP,CACTU,FRANK'

---The function does split

CREATE FUNCTION inline_split_me (@param varchar(7998)) RETURNS TABLE AS
RETURN(SELECT substring(',' + @param + ',', Number + 1,
charindex(',', ',' + @param + ',', Number + 1) -
Number - 1)
AS Value
FROM Numbers
WHERE Number <= len(',' + @param + ',') - 1
AND substring(',' + @param + ',', Number, 1) = ',')

SELECT TOP 8000 Number = IDENTITY(int, 1, 1)
INTO Numbers
FROM pubs..authors t1, pubs..authors t2, pubs..authors t3

drop table numbers
drop function inline_split_me
drop proc get_company_names_inline

"news.sbcglobal.net" <gr************@MAPSONsbcglobal.net> wrote in message
news:Iv*******************@newssvr12.news.prodigy. com...
Here's my problem:

I'm developing an ASP.NET 2.0 application that has a user select one or
more
auto manufacturers from a listbox ("lstMakes"). Once they do this,
another
listbox ("lstModels") should be filled with all matching models made by
the
selected manufacturers. If lstMakes was not multi-select, I'd have no
problem. But in this case it has to be multi-select. The database is SQL
Server 2005 which does not accept arrays as parameters. I've been told
that
I have to create an XML document that will act as a filtered Manufacturers
table that I can join to my Models table in my stored procedure. Problem
is
I don't have the foggiest idea how to do this. I've seen some examples
that
just leave me scratching my head so I was hoping someone could look at
what
I'm trying to do and show me how to do this. Thanks!

Jun 11 '06 #2
news.sbcglobal.net (gr************@MAPSONsbcglobal.net) writes:
I'm developing an ASP.NET 2.0 application that has a user select one or
more auto manufacturers from a listbox ("lstMakes"). Once they do this,
another listbox ("lstModels") should be filled with all matching models
made by the selected manufacturers. If lstMakes was not multi-select,
I'd have no problem. But in this case it has to be multi-select. The
database is SQL Server 2005 which does not accept arrays as parameters.
I've been told that I have to create an XML document that will act as a
filtered Manufacturers table that I can join to my Models table in my
stored procedure. Problem is I don't have the foggiest idea how to do
this. I've seen some examples that just leave me scratching my head so
I was hoping someone could look at what I'm trying to do and show me how
to do this. Thanks!


The good news is that XML is just one way to skin the cat, so if you
don't know how to create XML documents, you can sleep over that part
for now. Look at
http://www.sommarskog.se/arrays-in-sql.html#iterative for what is the
simplest method.

However, for more comlpex scenarios where you need to send down an
"array" of structure data, XML is the best apparoch. So you may want
learn how to form XML documents for future use anyway.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Lauren Quantrell | last post by:
Is there a way to create a text file (such as a Windows Notepad file) by using a trigger on a table? What I want to do is to send a row of information to a table where the table: tblFileData has...
4
by: MD | last post by:
I am trying to create a dynamic SQL statement to create a view. I have a stored procedure, which based on the parameters passed calls different stored procedures. Each of this sub stored procedure...
4
by: Robin Tucker | last post by:
Hi, I'm trying to determine with my program whether or not a given database supports a given feature set. To do this I'm querying for certain stored procedures in the sysobjects table and if...
2
by: Chris | last post by:
I installed SQLServer 2005 Standard Edition and tried to created a stored procedure in VB. From START/PROGRAMS/MICROSOFT VISUAL STUDIO 2005, I created a blank solution. What type of project shall I...
2
by: news.sbcglobal.net | last post by:
Here's my problem: I'm developing an ASP.NET 2.0 application that has a user select one or more auto manufacturers from a listbox ("lstMakes"). Once they do this, another listbox ("lstModels")...
2
by: masri999 | last post by:
I have a requirement in SQL 2005 in Development database 1. Schema dbo owns all objects (tables,views,SPs,UDFs etc) . 2. Only DBA's ( who are database owners ) can create, alter tables ....
6
by: Peter Nurse | last post by:
For reasons that are not relevant (though I explain them below *), I want, for all my users whatever privelige level, an SP which creates and inserts into a temporary table and then another SP...
2
by: Mukesh | last post by:
Hi all I m Using SQL SERVER 2005 I have a requirement to store some data in xmldatatype using stored procedure , Here is example
11
by: raylopez99 | last post by:
Keep in mind this is my first compiled SQL program Stored Procedure (SP), copied from a book by Frasier Visual C++.NET in Visual Studio 2005 (Chap12). So far, so theory, except for one bug...
1
by: DR | last post by:
what are the memory caps for threads running as a CLR stored procedure executed by sql server 2005? is it limited by OS only or also by sql servers memory limits? e.g. lets say my clr stored...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.