TSQL中的数组? [英] Array in TSQL?

查看:66
本文介绍了TSQL中的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我有一些代码可以添加新用户。新用户有一个可以与之关联的

项目的复选框列表。我想将这个

项目列表与新用户信息一起发送给TSQL。我猜想将所选项目组合成

如下:6,4,8,19,2。


执行以下操作:


INSERT into tblUser(fields)VALUES(data)

声明@userID为整数

SET @UserID = @@ IDENTITY

@Selected中每个项目的


INSERT到tblSelections(字段)VALUE(item,@ UserID)


我知道上面是不可能的,但可以做类似的事吗?我想b $ b不想从我的asp.net页面为每个项目运行一个proc ....


谢谢,


-

David Lozzi

Web应用程序开发人员
dlozzi @(删除 - 这个)delphi-ts.com

Hello,

I have some code that adds a new user. The new user has a checkboxlist of
items which they can be associated with. I would like to send this list of
items to TSQL along with the new user information. I would guess to combine
the selected items like so: "6,4,8,19,2".

Kind of do the following:

INSERT into tblUser (fields) VALUES (data)
Declare @userID as integer
SET @UserID = @@IDENTITY

for each item in @Selected
INSERT into tblSelections (field) VALUE (item, @UserID)

I know above isn''t exactly possible, but can something similiar be done? I
dont want to have to run a proc for each item from my asp.net pages....

Thanks,

--
David Lozzi
Web Applications Developer
dlozzi@(remove-this)delphi-ts.com


推荐答案

它每次最简单地调用一个proc是最容易定义的。你可以用
将逗号分隔的字符串传入proc中,然后用该字符串循环执行




当CharIndex(,,@ Selected)!= 0

开始

- 在第一个逗号代码之前获取价值


- 插入值代码


- 删除第一个值和逗号代码

结束

It would definetely be easiest to call a proc each time. Othewise you
could pass in the comma seperated string into the proc, and then do a
while loop with that string.

While CharIndex(",",@Selected) != 0
Begin
-- Get Value before first comma code

-- Insert value code

-- Delete first value and comma code
End


David Lozzi(Da********@nospam.nospam)写道:
David Lozzi (Da********@nospam.nospam) writes:
我有一些代码可以添加新用户。新用户有一个可以与之关联的项目的复选框列表。我想将这个
项目列表与新用户信息一起发送给TSQL。我猜想
将所选项目组合起来:6,4,8,19,2。 >
执行以下操作:

INSERT into tblUser(fields)VALUES(data)
将@userID声明为整数
SET @UserID = @@ IDENTITY

@Selected中的每个项目
INSERT into tblSelections(field)VALUE(item,@ UserID)

我知道上面的内容并不完全可能,但是可以做类似的事吗?我不希望从我的asp.net页面为每个项目运行一个proc ....
I have some code that adds a new user. The new user has a checkboxlist
of items which they can be associated with. I would like to send this
list of items to TSQL along with the new user information. I would guess
to combine the selected items like so: "6,4,8,19,2". >
Kind of do the following:

INSERT into tblUser (fields) VALUES (data)
Declare @userID as integer
SET @UserID = @@IDENTITY

for each item in @Selected
INSERT into tblSelections (field) VALUE (item, @UserID)

I know above isn''t exactly possible, but can something similiar be done? I
dont want to have to run a proc for each item from my asp.net pages....




参见 http://www.sommarskog.se/arrays-in-sql.html#iterative 对于某些

解决方案。

-

Erland Sommarskog,SQL Server MVP, es **** @ sommarskog.se


SQL Server SP3的联机书籍
http://www.microsoft.com/sql/techinf...2000/books .asp



See http://www.sommarskog.se/arrays-in-sql.html#iterative for some
solutions.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp


你错过了RDBMS的基础,真的需要一本书

或一堂课在你尝试编码之前。


你想要违反第一范式(1NF)。所有数据值都是

标量;没有阵列。每个属性都是

单独的列。


行不是记录;字段不是列;表格不是文件。


我们不会像tbl-那样使用愚蠢的冗余前缀。关于表名。

查找ISO-11179。


我希望你知道IDENTITY根据定义不能成为关系密钥。

但是你以错误的方式使用了一件坏事。它模仿了一个

顺序文件记录号码计数器,而无需你干预

你将它声明为DDL的一部分。


Do你知道检查数字,正则表达式或其他一些规则

来验证你的用户ID吗?


SQL是一种面向集合的语言,所以你可以将查询结果插入到

基表或可更新的VIEW中。你正在编写类似于3GL的SQL。

你需要比新闻组更多的帮助。

You have missed the foundations of RDBMS and really need to get a book
or a class before you try to code anything.

You want to violate First Normal Form (1NF). All data values are
scalar; there are no arrays. Each of those attribures would be a
separate column.

Rows are not records; fields are not columns; tables are not files.

We do not put silly redundant prefixes like "tbl-" on table names.
Look up ISO-11179.

I hope you know that IDENTITY cannot be a relational key by definition.
But you are using a bad thing in the wrong way. It mimics a
sequential file record number counter without your intervention when
you declare it as part of the DDL.

Do you know about check digits, a Regular Expression or some other rule
to validate your user id?

SQL is a set-oriented language, so you can insert a query result into a
base table or updatable VIEW. You are writing SQL like it was a 3GL.
You need a lot more help thanyou can get in a Newsgroup.


这篇关于TSQL中的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆