<p class="intro">declare @topN int ; select @topN=10; select top (@topN) * from TableName 一定要用() 否则无效 SQL 参数 declare @topN int; select @topN = 10; select top (@topN) * from TableName</p> <span style="font-family:'Courier New', monospace;line-height:normal;color:#333333;"> <ol> <li style="padding-left:10px;background-image:initial;background-attachment:initial;background-origin:initial;background-clip:initial;background-color:#ffffff;background-position:initial initial;background-repeat:initial initial;"><span style="color:#000000;"><span style="color:#7f0055;font-weight:bold;">declare</span><span style="color:#000000;"> @topN </span><span style="color:#7f0055;font-weight:bold;">int</span><span style="color:#000000;">; </span></span></li> <li style="padding-left:10px;background-image:initial;background-attachment:initial;background-origin:initial;background-clip:initial;background-color:#ffffff;background-position:initial initial;background-repeat:initial initial;"> <span style="color:#7f0055;font-weight:bold;">select</span><span style="color:#000000;"> @topN = 10; </span> </li> <li style="padding-left:10px;background-image:initial;background-attachment:initial;background-origin:initial;background-clip:initial;background-color:#ffffff;background-position:initial initial;background-repeat:initial initial;"><span style="color:#000000;"> </span></li> <li style="padding-left:10px;background-image:initial;background-attachment:initial;background-origin:initial;background-clip:initial;background-color:#ffffff;background-position:initial initial;background-repeat:initial initial;"> <span style="color:#7f0055;font-weight:bold;">select</span><span style="color:#000000;"> </span><span style="color:#7f0055;font-weight:bold;">top</span><span style="color:#000000;"> <b><span style="color:#cc33e5;font-size:14px;">(@topN)</span></b> * </span><span style="color:#7f0055;font-weight:bold;">from</span><span style="color:#000000;"> TableName <br> <br> 一定要用() 否则无效<br> <br> </span> </li> </ol> </span> SQL 参数 <style> .CodeEntity .code_pieces ul.piece_anchor{width:25px;position:absolute;top:25px;left:-30px;z-index:1000;} .CodeEntity .code_pieces ul.piece_anchor li{width:25px;background: #efe;margin-bottom:2px;} .CodeEntity .code_pieces ul.piece_anchor li{border-left:3px #40AA63 solid;border-right:3px #efe solid;} .CodeEntity .code_pieces ul.piece_anchor li:hover{border-right:3px #40AA63 solid;border-left:3px #efe solid;} .CodeEntity .code_pieces ul.piece_anchor li a{color: #333;padding: 3px 10px;} .CodeEntity .code_pieces .jump_to_code{visibility:hidden;position:relative;} .CodeEntity .code_pieces .code_piece:hover .jump_to_code{visibility:visible;} .CodeEntity .code_pieces .code_piece:hover .jump_to_code a{text-decoration:none;} .CodeEntity .code_pieces h2 i{float:right;font-style:normal;font-weight:normal;} .CodeEntity .code_pieces h2 i a{font-size:9pt;background: #FFFFFF;color:#00A;padding: 2px 5px;text-decoration:none;} </style> <!--<ul class="piece_anchor">--> <!--<li>$velocityCount</li>--> <!--</ul>--> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush: sql; auto-links: false; ">declare @topN int; select @topN = 10; select top (@topN) * from TableName </pre><div class="contentsignin">ログイン後にコピー</div></div>