简体   繁体   English

在mssql和行选择中转换

[英]Converting in mssql and row select

I have a serious question about mssql now.. 我现在有一个关于mssql的严重问题。

You see, there's a query made to select some values from an actual number in UInt64 您会看到有一个查询要从UInt64中的实际数字中选择一些值

 DECLARE @val bigint = 33689413311;
WHILE ( @val > 0 )
 BEGIN
  PRINT CONVERT(varchar(max),((@val%32)*100)/31)+'%'
  SET @val = @val/32
 END

The result of this query should be: 该查询的结果应为:

100% 100%

67% 67%

29% 29%

74% 74%

0% 0%

38% 38%

100% 100%

Now, I want this query to select only the top 100%, and not to print the other (67,29,74,0,38,100) 现在,我希望此查询仅选择前100%,而不打印其他(67,29,74,0,38,100)

Is there any method to do it?! 有什么方法吗?

This is a very strange request. 这是一个非常奇怪的要求。 What you have isn't a "query". 您拥有的不是“查询”。 It is t-sql code. 它是t-sql代码。 If you just want the first value, get rid of the while loop: 如果只需要第一个值,请摆脱while循环:

DECLARE @val bigint = 33689413311;
PRINT CONVERT(varchar(max),((@val%32)*100)/31)+'%'

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

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