<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 错误:“锚点和递归部分之间的类型不匹配";

        时间:2023-10-10

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

                  上一篇:SQL Server 中最优雅的生成排列的方法 下一篇:SQL 糟糕的存储过程执行计划性能——参数嗅探

                  相关文章

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

                    1. <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>