<legend id='P5sKc'><style id='P5sKc'><dir id='P5sKc'><q id='P5sKc'></q></dir></style></legend>

      <bdo id='P5sKc'></bdo><ul id='P5sKc'></ul>

    <tfoot id='P5sKc'></tfoot>

    <small id='P5sKc'></small><noframes id='P5sKc'>

        <i id='P5sKc'><tr id='P5sKc'><dt id='P5sKc'><q id='P5sKc'><span id='P5sKc'><b id='P5sKc'><form id='P5sKc'><ins id='P5sKc'></ins><ul id='P5sKc'></ul><sub id='P5sKc'></sub></form><legend id='P5sKc'></legend><bdo id='P5sKc'><pre id='P5sKc'><center id='P5sKc'></center></pre></bdo></b><th id='P5sKc'></th></span></q></dt></tr></i><div id='P5sKc'><tfoot id='P5sKc'></tfoot><dl id='P5sKc'><fieldset id='P5sKc'></fieldset></dl></div>

        CTE 错误:“锚点和递归部分之间的类型不匹配";

        CTE error: quot;Types don#39;t match between the anchor and the recursive partquot;(CTE 错误:“锚点和递归部分之间的类型不匹配;)

          <legend id='vhifF'><style id='vhifF'><dir id='vhifF'><q id='vhifF'></q></dir></style></legend>

          <tfoot id='vhifF'></tfoot>

            • <small id='vhifF'></small><noframes id='vhifF'>

                <tbody id='vhifF'></tbody>

                  <bdo id='vhifF'></bdo><ul id='vhifF'></ul>
                • <i id='vhifF'><tr id='vhifF'><dt id='vhifF'><q id='vhifF'><span id='vhifF'><b id='vhifF'><form id='vhifF'><ins id='vhifF'></ins><ul id='vhifF'></ul><sub id='vhifF'></sub></form><legend id='vhifF'></legend><bdo id='vhifF'><pre id='vhifF'><center id='vhifF'></center></pre></bdo></b><th id='vhifF'></th></span></q></dt></tr></i><div id='vhifF'><tfoot id='vhifF'></tfoot><dl id='vhifF'><fieldset id='vhifF'></fieldset></dl></div>
                • 本文介绍了CTE 错误:“锚点和递归部分之间的类型不匹配";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在执行以下语句:

                  ;WITH cte AS (
                    SELECT 
                      1 as rn, 
                      'name1' as nm
                    UNION ALL
                    SELECT 
                      rn + 1,
                      nm = 'name' + CAST((rn + 1) as varchar(255))
                    FROM cte a WHERE rn < 10)
                  SELECT * 
                  FROM cte
                  

                  ...以错误结束...

                  ...which finishes with the error...

                  Msg 240, Level 16, State 1, Line 2
                  Types don't match between the anchor and the recursive part in column "nm" of recursive query "cte".
                  

                  我哪里出错了?

                  推荐答案

                  正是它所说的:

                  'name1' 具有与 'name' + CAST((rn+1) as varchar(255)) 不同的数据类型

                  试试这个(未经测试)

                  ;with cte as
                  (
                  select 1 as rn, CAST('name1' as varchar(259)) as nm
                  union all
                  select rn+1,nm = 'name' + CAST((rn+1) as varchar(255))
                  from cte a where rn<10)
                  select * from cte
                  

                  基本上,您也必须确保长度匹配.对于递归位,如果再次失败,您可能必须使用 CAST('name' AS varchar(4))

                  Basically, you have to ensure the length matches too. For the recursive bit, you may have to use CAST('name' AS varchar(4)) if it fails again

                  这篇关于CTE 错误:“锚点和递归部分之间的类型不匹配";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Building a comma separated list?(建立一个逗号分隔的列表?)
                  Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                  How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                  Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
                  Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                  SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)

                      <small id='pu2Bn'></small><noframes id='pu2Bn'>

                        • <legend id='pu2Bn'><style id='pu2Bn'><dir id='pu2Bn'><q id='pu2Bn'></q></dir></style></legend>
                            <bdo id='pu2Bn'></bdo><ul id='pu2Bn'></ul>
                            <tfoot id='pu2Bn'></tfoot>

                            <i id='pu2Bn'><tr id='pu2Bn'><dt id='pu2Bn'><q id='pu2Bn'><span id='pu2Bn'><b id='pu2Bn'><form id='pu2Bn'><ins id='pu2Bn'></ins><ul id='pu2Bn'></ul><sub id='pu2Bn'></sub></form><legend id='pu2Bn'></legend><bdo id='pu2Bn'><pre id='pu2Bn'><center id='pu2Bn'></center></pre></bdo></b><th id='pu2Bn'></th></span></q></dt></tr></i><div id='pu2Bn'><tfoot id='pu2Bn'></tfoot><dl id='pu2Bn'><fieldset id='pu2Bn'></fieldset></dl></div>
                              <tbody id='pu2Bn'></tbody>