user3153042
user3153042

Reputation: 23

Converting in mssql and row select

I have a serious question about mssql now..

You see, there's a query made to select some values from an actual number in 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%

67%

29%

74%

0%

38%

100%

Now, I want this query to select only the top 100%, and not to print the other (67,29,74,0,38,100)

Is there any method to do it?!

Upvotes: 0

Views: 50

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270391

This is a very strange request. What you have isn't a "query". It is t-sql code. If you just want the first value, get rid of the while loop:

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

Upvotes: 1

Related Questions