且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将存储过程中的值插入一张表

更新时间:2023-01-12 11:59:32

首先,您的SELECT语句不是***的!为什么?由于许多原因...

在开始对查询进行编程"之前,您需要了解有关SQL的基本知识.

在这里,您可以获得msdn文章的基本列表:
针对初学者的SQL [ ^ ]
面向初学者的T-SQL挑战 [ ^ ]
加入提示 [查询提示 [表提示 [插入 [存储过程 [交易 [ ^ ]
SQL Server事务和错误处理 [
First of all, your SELECT statement is not optimal! Why? Because of many reasons...

Before you start "programming" queries, you need to get a basic knowlegde about SQL.

Here you got a basic list of msdn articles:
SQL for beginners[^]
T-SQL Challenges for beginners[^]
JOIN hints[^]
QUERY hints[^]
TABLE hints[^]
INSERT[^]
STORED PROCEDURE[^]
And something extra:
TRANSACTIONS[^]
SQL Server Transactions and Error Handling[^]


使用SELECT语句来澄清这种情况.由于尚未在select语句中定义任何联接,因此实际上是在执行笛卡尔乘积.这意味着所有三个表中的所有行都将与所有行匹配.

例如,如果表各有3行,则结果集为9行.这很可能不是您所追求的.

请参考 SQL联接 [
To clarify the situation with your SELECT statement. Because you haven''t defined any joins in the select statement, you''re actually performing a cartesian product. This means that all the rows from all the three tables will be matched with all rows.

For example, if the tables have 3 rows each, your result set is 9 rows. Most likely this isn''t what you''re after.

Please refer to SQL Joins[^]


尝试这个

Hi try this

insert into newtablename(field1,field2..)
select distinct userid,
            fullname,
            lastname,
            firstname,from tblUserProfile