我是SQL Server存储过程的新手。
我想将此C#代码转换为SQL Server存储过程。
int i = 0;
While(i >= 0)
{
int count = checkvalue(name); // function checkvalue return integer value. & name is string value like "rest-123".
if(count == 0)
{
-- insert query in which name is inserted to some table.
break;
}
i++;
string Tempname = string.Format("{0}-{1}", name, i); // This write string like "rest-123-1"
name = Tempname
}
我想知道
string Tempname = string.Format("{0}-{1}", name, i);
操作请指导我或提供编写此存储过程的参考。
答案 0 :(得分:2)
我同意评论者的意见,这是一个可怕的想法,你没有尝试发布代码。所以这是通用的例子。
那说: Looping and BREAK:
USE AdventureWorks2008R2;
GO
WHILE (SELECT AVG(ListPrice) FROM Production.Product) < $300
BEGIN
UPDATE Production.Product
SET ListPrice = ListPrice * 2
SELECT MAX(ListPrice) FROM Production.Product
IF (SELECT MAX(ListPrice) FROM Production.Product) > $500
BREAK
ELSE
CONTINUE
END
PRINT 'Too much for the market to bear';
String contatenation :(示例是sql列,但变量的工作方式相同,加号。注意NULL,如果打开DB设置,则字符串concat为null会产生null)
SELECT (LastName + ', ' + FirstName) AS Name
FROM Person.Person
ORDER BY LastName ASC, FirstName ASC;