简体   繁体   English

根据 SQL 中的现有行在表中插入记录

[英]Insert record in the table based on existing row in SQL

Please find the below sample data.请找到以下示例数据。 The first table contains 2 rows.第一个表包含 2 行。 I need to get the rows where ever it is begging with emp as next row with ID and Name as first row and rest of the columns remains same.我需要将 emp 乞求的行作为下一行,ID 和 Name 作为第一行,其余列保持不变。 Need your help to achieve the same.需要你的帮助来实现同样的目标。 Thank you.谢谢你。

在此处输入图片说明

You can use wildcards for this question您可以对这个问题使用通配符

SELECT ID,Name,sal,date FROM TABLE 
WHERE ID LIKE 'emp%

' Read more about wildcards '阅读有关通配符的更多信息

you can do it like this:你可以这样做:

INSERT  INTO Table2
(
    [ID], 
    [Name],
    [sal],
    [date]
)
SELECT  T2.[ID],
        CAST(T2.[ID] AS VARCHAR(20)),
        T2.[sal],
        T2.[date]
FROM    Table2   AS T2
WHERE   T2.[Name] LIKE 'emp%'

Please let me know if it solves your issue, or if some adjustments are needed如果它解决了您的问题,或者是否需要进行一些调整,请告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM