在 SQL Server 2000 中,如何将 {n} 个 0 添加到 nchar(n)? [英] In SQL Server 2000 how do you add {n} number of 0's to a nchar(n)?

查看:29
本文介绍了在 SQL Server 2000 中,如何将 {n} 个 0 添加到 nchar(n)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 SQL Server 2000,我不确定是否已经有一个函数可以将任意数量的 0 添加到 nchar(n),或者是否最好在功能?

I'm using SQL Server 2000 and I'm not sure if there is already a function to add any number of 0's to an nchar(n), or if this is best done in a function?

这看起来正确吗

  proc repeatingCh
     @n int, -- i/p n to some number of characters
     @ch nchar(1), --i/p character
     @ch_n nchar(n) out
  as
  begin
     declare @ch_n as nchar(n)
     set @ch_n = ''

     for(i=1 to n)
     begin
        @ch_n = @ch_n + @ch
     end

     return 1
  end

我想在 sproc 或...很可能是一个函数中调用它并返回重复的字符.

I want to call it in a sproc or... most likely a function and return the repeating characters.

推荐答案

我又来了 ;)您可以为此使用 REPLICATE:

me again ;) You can use REPLICATE for this:

SELECT REPLICATE('0', 10)

这篇关于在 SQL Server 2000 中,如何将 {n} 个 0 添加到 nchar(n)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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