简体   繁体   中英

how can I limit the maximum of the number of variables (sql variables) to 100

I have a view table which has the following

CAST(ROUND(SUM(dbo.TR.Score * 100) AS int) AS ScoreReached

I want to limit the number of ScoreReached to only 100 (cannot larger than 100)

can i do that?

SELECT TOP 100 CAST(ROUND(SUM(dbo.TR.Score * 100) AS int) AS ScoreReached
FROM MyTable

If I understood your question right. This is syntax for TSQL, you can check syntax for others here .

You could use CASE ... WHEN syntax to constraint the value of ScoreReached column

SELECT CASE 
         WHEN TBL.ScoreReached > 100 THEN 100 
         ELSE TBL.ScoreReached 
       END AS ScoreReached
FROM   (SELECT CAST(ROUND(SUM(dbo.TR.Score * 100), 0) AS INT) AS ScoreReached 
        FROM   <your table name>) TBL 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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