Unix Technical Forum

SQL server stored procedure question

This is a discussion on SQL server stored procedure question within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi, I have a problem here when I code stored procedure to manipulate data in database. My idea is ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 05:24 PM
mingzhen
 
Posts: n/a
Default SQL server stored procedure question

Hi,

I have a problem here when I code stored procedure to manipulate data
in database. My idea is that if I can save all data I get in some
arrays I should be able to manipulate the arrays directly. But I do
not know how to declare arrays in SQL server stored procedure and do
not know other ways to do the same thing. Please help me out. Thanks
in advance.

-mingzhen
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 05:24 PM
Anith Sen
 
Posts: n/a
Default Re: SQL server stored procedure question

There are no 'arrays' or array datatypes in SQL Server. Generally developers
come up with many work arounds using strings, XML etc. You can find an
exhaustive article at :
http://www.algonet.se/~sommar/arrays-in-sql.html

--
- Anith
( Please reply to newsgroups only )


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 05:25 PM
Erland Sommarskog
 
Posts: n/a
Default Re: SQL server stored procedure question

[posted and mailed, please reply in public]

mingzhen (mingzhen401@yahoo.com) writes:
> I have a problem here when I code stored procedure to manipulate data
> in database. My idea is that if I can save all data I get in some
> arrays I should be able to manipulate the arrays directly. But I do
> not know how to declare arrays in SQL server stored procedure and do
> not know other ways to do the same thing. Please help me out. Thanks
> in advance.


It sounds like you are used to programming in 3GL, and want to apply
the same methods there. Actually, there are arrays in SQL, just
there right before your eyes. But they are not called arrays, but
tables, and are in many extents much more powerful than arrays. Arrays
you typically handle sequentially. While you can do this with a table,
you can also apply operations on many rows at the same time, which is
usually several magnitudes faster than sequential processeing.

--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 05:25 PM
mingzhen
 
Posts: n/a
Default Re: SQL server stored procedure question

Yes, I know that sometimes table can be more flexible than arrays. But
my main problem is that I want to abstract data from each record in
the table, and concatenate these dat a into one string. Then I can
compare these strings to chech if there are some duplicate records in
the specific table.

So, my problems are:
1. identify primary key field in a specific table
2. concatenate data from fields except primary key field in one record
into one string, and different strings for different records in the
table

HOw can I do this using table or other methods? Thanks for help.

--mingzhen


Erland Sommarskog <sommar@algonet.se> wrote in message news:<Xns93D1B99A07EYazorman@127.0.0.1>...
> [posted and mailed, please reply in public]
>
> mingzhen (mingzhen401@yahoo.com) writes:
> > I have a problem here when I code stored procedure to manipulate data
> > in database. My idea is that if I can save all data I get in some
> > arrays I should be able to manipulate the arrays directly. But I do
> > not know how to declare arrays in SQL server stored procedure and do
> > not know other ways to do the same thing. Please help me out. Thanks
> > in advance.

>
> It sounds like you are used to programming in 3GL, and want to apply
> the same methods there. Actually, there are arrays in SQL, just
> there right before your eyes. But they are not called arrays, but
> tables, and are in many extents much more powerful than arrays. Arrays
> you typically handle sequentially. While you can do this with a table,
> you can also apply operations on many rows at the same time, which is
> usually several magnitudes faster than sequential processeing.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 05:25 PM
Erland Sommarskog
 
Posts: n/a
Default Re: SQL server stored procedure question

mingzhen (mingzhen401@yahoo.com) writes:
> Yes, I know that sometimes table can be more flexible than arrays. But
> my main problem is that I want to abstract data from each record in
> the table, and concatenate these dat a into one string. Then I can
> compare these strings to chech if there are some duplicate records in
> the specific table.
>
> So, my problems are:
> 1. identify primary key field in a specific table
> 2. concatenate data from fields except primary key field in one record
> into one string, and different strings for different records in the
> table
>
> HOw can I do this using table or other methods? Thanks for help.


I'm really sure that I follow, so I like to make the following standard
suggestion. Post a script that contains CREATE TABLE statement(s) for
the involved table(s) (preferably simplified) and INSERT statements
with sample data. With the script, include the desired result.

--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:02 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com