编程趣事:SQL Error 191

软件开发里有很多有趣的事情,你通常只接触某种特定类型的应用,见识太少。比如,这HTTP 414 错误:请求的URI太长。对于这个长度没有一个标准的上限,很多web服务器都没有说明多长的GET请求会太长。

当我在维护这家公司的服务处的应用时,Ben在SQL Server里发现了一个相似类型的错误。

Incorrect syntax near '('.
//你的一部分SQL语句嵌套的太深。
Some part of your SQL statement is nested too deeply. 
//请重写你的查询语句,或把它们分成小语句。
Rewrite the query or break it up into smaller queries.

错误代码是Error 191——又是一个没有标准上限的错误——由下面的查询语句触发。

SELECT DISTINCT COUNT(Task.RecId) 
  FROM Task 
 WHERE (Task.TaskType = @P514) 
   AND (Task.Status = @P1) 
   AND (Task.RecId is not null)
   AND ((((((((((((((((((((((((((((((((((((((((((((((((((((
       ((((((((((((((((((((((((((((((((((((((((((((((((((((
       ((((((((((((((((((((((((((((((((((((((((((((((((((((
       ((((((((((((((((((((((((((((((((((((((((((((((((((((
       ((((((((((((((((((((((((((((((((((((((((((((((((((((
       ((((((((((((((((((((((((((((((((((((((((((((((((((((
       ((((((((((((((((((((((((((((((((((((((((((((((((((((
       ((((((((((((((((((((((((((((((((((((((((((((((((((((
       ((((((((((((((((((((((((((((((((((((((((((((((((((((
       (((((((((((((((((((((((((((((((((((((((((((
            (Task.OwnerTeam = @P2) 
            AND (Task.OwnerTeam = @P3)) 
            AND (Task.OwnerTeam = @P4)) 
            AND (Task.OwnerTeam = @P5)) 
            AND (Task.OwnerTeam = @P6)) 
            AND (Task.OwnerTeam = @P7)) 
            AND (Task.OwnerTeam = @P8)) 
            AND (Task.OwnerTeam = @P9)) 
            AND (Task.OwnerTeam = @P10)) 
            AND (Task.OwnerTeam = @P11)) 
            AND (Task.OwnerTeam = @P12)) 
            AND (Task.OwnerTeam = @P13)) 
            AND (Task.OwnerTeam = @P14)) 
            AND (Task.OwnerTeam = @P15)) 
            AND (Task.OwnerTeam = @P16)) 
            AND (Task.OwnerTeam = @P17)) 
            AND (Task.OwnerTeam = @P18)) 
            AND (Task.OwnerTeam = @P19)) 
            AND (Task.OwnerTeam = @P20)) 
            AND (Task.OwnerTeam = @P21)) 
            AND (Task.OwnerTeam = @P22)) 
            AND (Task.OwnerTeam = @P23)) 
            AND (Task.OwnerTeam = @P24)) 
            AND (Task.OwnerTeam = @P25)) 
            AND (Task.OwnerTeam = @P26)) 
            AND (Task.OwnerTeam = @P27)) 
            AND (Task.OwnerTeam = @P28)) 
            AND (Task.OwnerTeam = @P29)) 
            AND (Task.OwnerTeam = @P30)) 
            AND (Task.OwnerTeam = @P31)) 
            AND (Task.OwnerTeam = @P32)) 
            AND (Task.OwnerTeam = @P33)) 
            AND (Task.OwnerTeam = @P34)) 
            AND (Task.OwnerTeam = @P35)) 
            AND (Task.OwnerTeam = @P36)) 
            AND (Task.OwnerTeam = @P37)) 
            AND (Task.OwnerTeam = @P38)) 
            AND (Task.OwnerTeam = @P39)) 
            AND (Task.OwnerTeam = @P40)) 
            AND (Task.OwnerTeam = @P41)) 
            AND (Task.OwnerTeam = @P42)) 
            AND (Task.OwnerTeam = @P43)) 
            AND (Task.OwnerTeam = @P44)) 
            AND (Task.OwnerTeam = @P45)) 
            AND (Task.OwnerTeam = @P46)) 
            AND (Task.OwnerTeam = @P47)) 
            AND (Task.OwnerTeam = @P48)) 
            AND (Task.OwnerTeam = @P49)) 
            AND (Task.OwnerTeam = @P50)) 
            AND (Task.OwnerTeam = @P51)) 
            AND (Task.OwnerTeam = @P52)) 
            AND (Task.OwnerTeam = @P53)) 
            AND (Task.OwnerTeam = @P54)) 
            AND (Task.OwnerTeam = @P55)) 
            AND (Task.OwnerTeam = @P56)) 
            AND (Task.OwnerTeam = @P57)) 
            AND (Task.OwnerTeam = @P58)) 
            AND (Task.OwnerTeam = @P59)) 
            AND (Task.OwnerTeam = @P60)) 
            AND (Task.OwnerTeam = @P61)) 
            AND (Task.OwnerTeam = @P62)) 
            AND (Task.OwnerTeam = @P63)) 
            AND (Task.OwnerTeam = @P64)) 
            AND (Task.OwnerTeam = @P65)) 
            AND (Task.OwnerTeam = @P66)) 
            AND (Task.OwnerTeam = @P67)) 
            AND (Task.OwnerTeam = @P68)) 
            AND (Task.OwnerTeam = @P69)) 
            AND (Task.OwnerTeam = @P70)) 
            AND (Task.OwnerTeam = @P71)) 
            AND (Task.OwnerTeam = @P72)) 
            AND (Task.OwnerTeam = @P73)) 
            AND (Task.OwnerTeam = @P74)) 
            AND (Task.OwnerTeam = @P75)) 
            AND (Task.OwnerTeam = @P76)) 
            AND (Task.OwnerTeam = @P77)) 
            AND (Task.OwnerTeam = @P78)) 
            AND (Task.OwnerTeam = @P79)) 
            AND (Task.OwnerTeam = @P80)) 
            AND (Task.OwnerTeam = @P81)) 
            AND (Task.OwnerTeam = @P82)) 
            AND (Task.OwnerTeam = @P83)) 
            AND (Task.OwnerTeam = @P84)) 
            AND (Task.OwnerTeam = @P85)) 
            AND (Task.OwnerTeam = @P86)) 
            AND (Task.OwnerTeam = @P87)) 
            AND (Task.OwnerTeam = @P88)) 
            AND (Task.OwnerTeam = @P89)) 
            AND (Task.OwnerTeam = @P90)) 
            AND (Task.OwnerTeam = @P91)) 
            AND (Task.OwnerTeam = @P92)) 
            AND (Task.OwnerTeam = @P93)) 
            AND (Task.OwnerTeam = @P94)) 
            AND (Task.OwnerTeam = @P95)) 
            AND (Task.OwnerTeam = @P96)) 
            AND (Task.OwnerTeam = @P97)) 
            AND (Task.OwnerTeam = @P98)) 
            AND (Task.OwnerTeam = @P99)) 
            AND (Task.OwnerTeam = @P100)) 
            AND (Task.OwnerTeam = @P101)) 
            AND (Task.OwnerTeam = @P102)) 
            AND (Task.OwnerTeam = @P103)) 
            AND (Task.OwnerTeam = @P104)) 
            AND (Task.OwnerTeam = @P105)) 
            AND (Task.OwnerTeam = @P106)) 
            AND (Task.OwnerTeam = @P107)) 
            AND (Task.OwnerTeam = @P108)) 
            AND (Task.OwnerTeam = @P109)) 
            AND (Task.OwnerTeam = @P110)) 
            AND (Task.OwnerTeam = @P111)) 
            AND (Task.OwnerTeam = @P112)) 
            AND (Task.OwnerTeam = @P113)) 
            AND (Task.OwnerTeam = @P114)) 
            AND (Task.OwnerTeam = @P115)) 
            AND (Task.OwnerTeam = @P116)) 
            AND (Task.OwnerTeam = @P117)) 
            AND (Task.OwnerTeam = @P118)) 
            AND (Task.OwnerTeam = @P119)) 
            AND (Task.OwnerTeam = @P120)) 
            AND (Task.OwnerTeam = @P121)) 
            AND (Task.OwnerTeam = @P122)) 
            AND (Task.OwnerTeam = @P123)) 
            AND (Task.OwnerTeam = @P124)) 
            AND (Task.OwnerTeam = @P125)) 
            AND (Task.OwnerTeam = @P126)) 
            AND (Task.OwnerTeam = @P127)) 
            AND (Task.OwnerTeam = @P128)) 
            AND (Task.OwnerTeam = @P129)) 
            AND (Task.OwnerTeam = @P130)) 
            AND (Task.OwnerTeam = @P131)) 
            AND (Task.OwnerTeam = @P132)) 
            AND (Task.OwnerTeam = @P133)) 
            AND (Task.OwnerTeam = @P134)) 
            AND (Task.OwnerTeam = @P135)) 
            AND (Task.OwnerTeam = @P136)) 
            AND (Task.OwnerTeam = @P137)) 
            AND (Task.OwnerTeam = @P138)) 
            AND (Task.OwnerTeam = @P139)) 
            AND (Task.OwnerTeam = @P140)) 
            AND (Task.OwnerTeam = @P141)) 
            AND (Task.OwnerTeam = @P142)) 
            AND (Task.OwnerTeam = @P143)) 
            AND (Task.OwnerTeam = @P144)) 
            AND (Task.OwnerTeam = @P145)) 
            AND (Task.OwnerTeam = @P146)) 
            AND (Task.OwnerTeam = @P147)) 
            AND (Task.OwnerTeam = @P148)) 
            AND (Task.OwnerTeam = @P149)) 
            AND (Task.OwnerTeam = @P150)) 
            AND (Task.OwnerTeam = @P151)) 
            AND (Task.OwnerTeam = @P152)) 
            AND (Task.OwnerTeam = @P153)) 
            AND (Task.OwnerTeam = @P154)) 
            AND (Task.OwnerTeam = @P155)) 
            AND (Task.OwnerTeam = @P156)) 
            AND (Task.OwnerTeam = @P157)) 
            AND (Task.OwnerTeam = @P158)) 
            AND (Task.OwnerTeam = @P159)) 
            AND (Task.OwnerTeam = @P160)) 
            AND (Task.OwnerTeam = @P161)) 
            AND (Task.OwnerTeam = @P162)) 
            AND (Task.OwnerTeam = @P163)) 
            AND (Task.OwnerTeam = @P164)) 
            AND (Task.OwnerTeam = @P165)) 
            AND (Task.OwnerTeam = @P166)) 
            AND (Task.OwnerTeam = @P167)) 
            AND (Task.OwnerTeam = @P168)) 
            AND (Task.OwnerTeam = @P169)) 
            AND (Task.OwnerTeam = @P170)) 
            AND (Task.OwnerTeam = @P171)) 
            AND (Task.OwnerTeam = @P172)) 
            AND (Task.OwnerTeam = @P173)) 
            AND (Task.OwnerTeam = @P174)) 
            AND (Task.OwnerTeam = @P175)) 
            AND (Task.OwnerTeam = @P176)) 
            AND (Task.OwnerTeam = @P177)) 
            AND (Task.OwnerTeam = @P178)) 
            AND (Task.OwnerTeam = @P179)) 
            AND (Task.OwnerTeam = @P180)) 
            AND (Task.OwnerTeam = @P181)) 
            AND (Task.OwnerTeam = @P182)) 
            AND (Task.OwnerTeam = @P183)) 
            AND (Task.OwnerTeam = @P184)) 
            AND (Task.OwnerTeam = @P185)) 
            AND (Task.OwnerTeam = @P186)) 
            AND (Task.OwnerTeam = @P187)) 
            AND (Task.OwnerTeam = @P188)) 
            AND (Task.OwnerTeam = @P189)) 
            AND (Task.OwnerTeam = @P190)) 
            AND (Task.OwnerTeam = @P191)) 
            AND (Task.OwnerTeam = @P192)) 
            AND (Task.OwnerTeam = @P193)) 
            AND (Task.OwnerTeam = @P194)) 
            AND (Task.OwnerTeam = @P195)) 
            AND (Task.OwnerTeam = @P196)) 
            AND (Task.OwnerTeam = @P197)) 
            AND (Task.OwnerTeam = @P198)) 
            AND (Task.OwnerTeam = @P199)) 
            AND (Task.OwnerTeam = @P200)) 
            AND (Task.OwnerTeam = @P201)) 
            AND (Task.OwnerTeam = @P202)) 
            AND (Task.OwnerTeam = @P203)) 
            AND (Task.OwnerTeam = @P204)) 
            AND (Task.OwnerTeam = @P205)) 
            AND (Task.OwnerTeam = @P206)) 
            AND (Task.OwnerTeam = @P207)) 
            AND (Task.OwnerTeam = @P208)) 
            AND (Task.OwnerTeam = @P209)) 
            AND (Task.OwnerTeam = @P210)) 
            AND (Task.OwnerTeam = @P211)) 
            AND (Task.OwnerTeam = @P212)) 
            AND (Task.OwnerTeam = @P213)) 
            AND (Task.OwnerTeam = @P214)) 
            AND (Task.OwnerTeam = @P215)) 
            AND (Task.OwnerTeam = @P216)) 
            AND (Task.OwnerTeam = @P217)) 
            AND (Task.OwnerTeam = @P218)) 
            AND (Task.OwnerTeam = @P219)) 
            AND (Task.OwnerTeam = @P220)) 
            AND (Task.OwnerTeam = @P221)) 
            AND (Task.OwnerTeam = @P222)) 
            AND (Task.OwnerTeam = @P223)) 
            AND (Task.OwnerTeam = @P224)) 
            AND (Task.OwnerTeam = @P225)) 
            AND (Task.OwnerTeam = @P226)) 
            AND (Task.OwnerTeam = @P227)) 
            AND (Task.OwnerTeam = @P228)) 
            AND (Task.OwnerTeam = @P229)) 
            AND (Task.OwnerTeam = @P230)) 
            AND (Task.OwnerTeam = @P231)) 
            AND (Task.OwnerTeam = @P232)) 
            AND (Task.OwnerTeam = @P233)) 
            AND (Task.OwnerTeam = @P234)) 
            AND (Task.OwnerTeam = @P235)) 
            AND (Task.OwnerTeam = @P236)) 
            AND (Task.OwnerTeam = @P237)) 
            AND (Task.OwnerTeam = @P238)) 
            AND (Task.OwnerTeam = @P239)) 
            AND (Task.OwnerTeam = @P240)) 
            AND (Task.OwnerTeam = @P241)) 
            AND (Task.OwnerTeam = @P242)) 
            AND (Task.OwnerTeam = @P243)) 
            AND (Task.OwnerTeam = @P244)) 
            AND (Task.OwnerTeam = @P245)) 
            AND (Task.OwnerTeam = @P246)) 
            AND (Task.OwnerTeam = @P247)) 
            AND (Task.OwnerTeam = @P248)) 
            AND (Task.OwnerTeam = @P249)) 
            AND (Task.OwnerTeam = @P250)) 
            AND (Task.OwnerTeam = @P251)) 
            AND (Task.OwnerTeam = @P252)) 
            AND (Task.OwnerTeam = @P253)) 
            AND (Task.OwnerTeam = @P254)) 
            AND (Task.OwnerTeam = @P255)) 
            AND (Task.OwnerTeam = @P256)) 
            AND (Task.OwnerTeam = @P257)) 
            AND (Task.OwnerTeam = @P258)) 
            AND (Task.OwnerTeam = @P259)) 
            AND (Task.OwnerTeam = @P260)) 
            AND (Task.OwnerTeam = @P261)) 
            AND (Task.OwnerTeam = @P262)) 
            AND (Task.OwnerTeam = @P263)) 
            AND (Task.OwnerTeam = @P264)) 
            AND (Task.OwnerTeam = @P265)) 
            AND (Task.OwnerTeam = @P266)) 
            AND (Task.OwnerTeam = @P267)) 
            AND (Task.OwnerTeam = @P268)) 
            AND (Task.OwnerTeam = @P269)) 
            AND (Task.OwnerTeam = @P270)) 
            AND (Task.OwnerTeam = @P271)) 
            AND (Task.OwnerTeam = @P272)) 
            AND (Task.OwnerTeam = @P273)) 
            AND (Task.OwnerTeam = @P274)) 
            AND (Task.OwnerTeam = @P275)) 
            AND (Task.OwnerTeam = @P276)) 
            AND (Task.OwnerTeam = @P277)) 
            AND (Task.OwnerTeam = @P278)) 
            AND (Task.OwnerTeam = @P279)) 
            AND (Task.OwnerTeam = @P280)) 
            AND (Task.OwnerTeam = @P281)) 
            AND (Task.OwnerTeam = @P282)) 
            AND (Task.OwnerTeam = @P283)) 
            AND (Task.OwnerTeam = @P284)) 
            AND (Task.OwnerTeam = @P285)) 
            AND (Task.OwnerTeam = @P286)) 
            AND (Task.OwnerTeam = @P287)) 
            AND (Task.OwnerTeam = @P288)) 
            AND (Task.OwnerTeam = @P289)) 
            AND (Task.OwnerTeam = @P290)) 
            AND (Task.OwnerTeam = @P291)) 
            AND (Task.OwnerTeam = @P292)) 
            AND (Task.OwnerTeam = @P293)) 
            AND (Task.OwnerTeam = @P294)) 
            AND (Task.OwnerTeam = @P295)) 
            AND (Task.OwnerTeam = @P296)) 
            AND (Task.OwnerTeam = @P297)) 
            AND (Task.OwnerTeam = @P298)) 
            AND (Task.OwnerTeam = @P299)) 
            AND (Task.OwnerTeam = @P300)) 
            AND (Task.OwnerTeam = @P301)) 
            AND (Task.OwnerTeam = @P302)) 
            AND (Task.OwnerTeam = @P303)) 
            AND (Task.OwnerTeam = @P304)) 
            AND (Task.OwnerTeam = @P305)) 
            AND (Task.OwnerTeam = @P306)) 
            AND (Task.OwnerTeam = @P307)) 
            AND (Task.OwnerTeam = @P308)) 
            AND (Task.OwnerTeam = @P309)) 
            AND (Task.OwnerTeam = @P310)) 
            AND (Task.OwnerTeam = @P311)) 
            AND (Task.OwnerTeam = @P312)) 
            AND (Task.OwnerTeam = @P313)) 
            AND (Task.OwnerTeam = @P314)) 
            AND (Task.OwnerTeam = @P315)) 
            AND (Task.OwnerTeam = @P316)) 
            AND (Task.OwnerTeam = @P317)) 
            AND (Task.OwnerTeam = @P318)) 
            AND (Task.OwnerTeam = @P319)) 
            AND (Task.OwnerTeam = @P320)) 
            AND (Task.OwnerTeam = @P321)) 
            AND (Task.OwnerTeam = @P322)) 
            AND (Task.OwnerTeam = @P323)) 
            AND (Task.OwnerTeam = @P324)) 
            AND (Task.OwnerTeam = @P325)) 
            AND (Task.OwnerTeam = @P326)) 
            AND (Task.OwnerTeam = @P327)) 
            AND (Task.OwnerTeam = @P328)) 
            AND (Task.OwnerTeam = @P329)) 
            AND (Task.OwnerTeam = @P330)) 
            AND (Task.OwnerTeam = @P331)) 
            AND (Task.OwnerTeam = @P332)) 
            AND (Task.OwnerTeam = @P333)) 
            AND (Task.OwnerTeam = @P334)) 
            AND (Task.OwnerTeam = @P335)) 
            AND (Task.OwnerTeam = @P336)) 
            AND (Task.OwnerTeam = @P337)) 
            AND (Task.OwnerTeam = @P338)) 
            AND (Task.OwnerTeam = @P339)) 
            AND (Task.OwnerTeam = @P340)) 
            AND (Task.OwnerTeam = @P341)) 
            AND (Task.OwnerTeam = @P342)) 
            AND (Task.OwnerTeam = @P343)) 
            AND (Task.OwnerTeam = @P344)) 
            AND (Task.OwnerTeam = @P345)) 
            AND (Task.OwnerTeam = @P346)) 
            AND (Task.OwnerTeam = @P347)) 
            AND (Task.OwnerTeam = @P348)) 
            AND (Task.OwnerTeam = @P349)) 
            AND (Task.OwnerTeam = @P350)) 
            AND (Task.OwnerTeam = @P351)) 
            AND (Task.OwnerTeam = @P352)) 
            AND (Task.OwnerTeam = @P353)) 
            AND (Task.OwnerTeam = @P354)) 
            AND (Task.OwnerTeam = @P355)) 
            AND (Task.OwnerTeam = @P356)) 
            AND (Task.OwnerTeam = @P357)) 
            AND (Task.OwnerTeam = @P358)) 
            AND (Task.OwnerTeam = @P359)) 
            AND (Task.OwnerTeam = @P360)) 
            AND (Task.OwnerTeam = @P361)) 
            AND (Task.OwnerTeam = @P362)) 
            AND (Task.OwnerTeam = @P363)) 
            AND (Task.OwnerTeam = @P364)) 
            AND (Task.OwnerTeam = @P365)) 
            AND (Task.OwnerTeam = @P366)) 
            AND (Task.OwnerTeam = @P367)) 
            AND (Task.OwnerTeam = @P368)) 
            AND (Task.OwnerTeam = @P369)) 
            AND (Task.OwnerTeam = @P370)) 
            AND (Task.OwnerTeam = @P371)) 
            AND (Task.OwnerTeam = @P372)) 
            AND (Task.OwnerTeam = @P373)) 
            AND (Task.OwnerTeam = @P374)) 
            AND (Task.OwnerTeam = @P375)) 
            AND (Task.OwnerTeam = @P376)) 
            AND (Task.OwnerTeam = @P377)) 
            AND (Task.OwnerTeam = @P378)) 
            AND (Task.OwnerTeam = @P379)) 
            AND (Task.OwnerTeam = @P380)) 
            AND (Task.OwnerTeam = @P381)) 
            AND (Task.OwnerTeam = @P382)) 
            AND (Task.OwnerTeam = @P383)) 
            AND (Task.OwnerTeam = @P384)) 
            AND (Task.OwnerTeam = @P385)) 
            AND (Task.OwnerTeam = @P386)) 
            AND (Task.OwnerTeam = @P387)) 
            AND (Task.OwnerTeam = @P388)) 
            AND (Task.OwnerTeam = @P389)) 
            AND (Task.OwnerTeam = @P390)) 
            AND (Task.OwnerTeam = @P391)) 
            AND (Task.OwnerTeam = @P392)) 
            AND (Task.OwnerTeam = @P393)) 
            AND (Task.OwnerTeam = @P394)) 
            AND (Task.OwnerTeam = @P395)) 
            AND (Task.OwnerTeam = @P396)) 
            AND (Task.OwnerTeam = @P397)) 
            AND (Task.OwnerTeam = @P398)) 
            AND (Task.OwnerTeam = @P399)) 
            AND (Task.OwnerTeam = @P400)) 
            AND (Task.OwnerTeam = @P401)) 
            AND (Task.OwnerTeam = @P402)) 
            AND (Task.OwnerTeam = @P403)) 
            AND (Task.OwnerTeam = @P404)) 
            AND (Task.OwnerTeam = @P405)) 
            AND (Task.OwnerTeam = @P406)) 
            AND (Task.OwnerTeam = @P407)) 
            AND (Task.OwnerTeam = @P408)) 
            AND (Task.OwnerTeam = @P409)) 
            AND (Task.OwnerTeam = @P410)) 
            AND (Task.OwnerTeam = @P411)) 
            AND (Task.OwnerTeam = @P412)) 
            AND (Task.OwnerTeam = @P413)) 
            AND (Task.OwnerTeam = @P414)) 
            AND (Task.OwnerTeam = @P415)) 
            AND (Task.OwnerTeam = @P416)) 
            AND (Task.OwnerTeam = @P417)) 
            AND (Task.OwnerTeam = @P418)) 
            AND (Task.OwnerTeam = @P419)) 
            AND (Task.OwnerTeam = @P420)) 
            AND (Task.OwnerTeam = @P421)) 
            AND (Task.OwnerTeam = @P422)) 
            AND (Task.OwnerTeam = @P423)) 
            AND (Task.OwnerTeam = @P424)) 
            AND (Task.OwnerTeam = @P425)) 
            AND (Task.OwnerTeam = @P426)) 
            AND (Task.OwnerTeam = @P427)) 
            AND (Task.OwnerTeam = @P428)) 
            AND (Task.OwnerTeam = @P429)) 
            AND (Task.OwnerTeam = @P430)) 
            AND (Task.OwnerTeam = @P431)) 
            AND (Task.OwnerTeam = @P432)) 
            AND (Task.OwnerTeam = @P433)) 
            AND (Task.OwnerTeam = @P434)) 
            AND (Task.OwnerTeam = @P435)) 
            AND (Task.OwnerTeam = @P436)) 
            AND (Task.OwnerTeam = @P437)) 
            AND (Task.OwnerTeam = @P438)) 
            AND (Task.OwnerTeam = @P439)) 
            AND (Task.OwnerTeam = @P440)) 
            AND (Task.OwnerTeam = @P441)) 
            AND (Task.OwnerTeam = @P442)) 
            AND (Task.OwnerTeam = @P443)) 
            AND (Task.OwnerTeam = @P444)) 
            AND (Task.OwnerTeam = @P445)) 
            AND (Task.OwnerTeam = @P446)) 
            AND (Task.OwnerTeam = @P447)) 
            AND (Task.OwnerTeam = @P448)) 
            AND (Task.OwnerTeam = @P449)) 
            AND (Task.OwnerTeam = @P450)) 
            AND (Task.OwnerTeam = @P451)) 
            AND (Task.OwnerTeam = @P452)) 
            AND (Task.OwnerTeam = @P453)) 
            AND (Task.OwnerTeam = @P454)) 
            AND (Task.OwnerTeam = @P455)) 
            AND (Task.OwnerTeam = @P456)) 
            AND (Task.OwnerTeam = @P457)) 
            AND (Task.OwnerTeam = @P458)) 
            AND (Task.OwnerTeam = @P459)) 
            AND (Task.OwnerTeam = @P460)) 
            AND (Task.OwnerTeam = @P461)) 
            AND (Task.OwnerTeam = @P462)) 
            AND (Task.OwnerTeam = @P463)) 
            AND (Task.OwnerTeam = @P464)) 
            AND (Task.OwnerTeam = @P465)) 
            AND (Task.OwnerTeam = @P466)) 
            AND (Task.OwnerTeam = @P467)) 
            AND (Task.OwnerTeam = @P468)) 
            AND (Task.OwnerTeam = @P469)) 
            AND (Task.OwnerTeam = @P470)) 
            AND (Task.OwnerTeam = @P471)) 
            AND (Task.OwnerTeam = @P472)) 
            AND (Task.OwnerTeam = @P473)) 
            AND (Task.OwnerTeam = @P474)) 
            AND (Task.OwnerTeam = @P475)) 
            AND (Task.OwnerTeam = @P476)) 
            AND (Task.OwnerTeam = @P477)) 
            AND (Task.OwnerTeam = @P478)) 
            AND (Task.OwnerTeam = @P479)) 
            AND (Task.OwnerTeam = @P480)) 
            AND (Task.OwnerTeam = @P481)) 
            AND (Task.OwnerTeam = @P482)) 
            AND (Task.OwnerTeam = @P483)) 
            AND (Task.OwnerTeam = @P484)) 
            AND (Task.OwnerTeam = @P485)) 
            AND (Task.OwnerTeam = @P486)) 
            AND (Task.OwnerTeam = @P487)) 
            AND (Task.OwnerTeam = @P488)) 
            AND (Task.OwnerTeam = @P489)) 
            AND (Task.OwnerTeam = @P490)) 
            AND (Task.OwnerTeam = @P491)) 
            AND (Task.OwnerTeam = @P492)) 
            AND (Task.OwnerTeam = @P493)) 
            AND (Task.OwnerTeam = @P494)) 
            AND (Task.OwnerTeam = @P495)) 
            AND (Task.OwnerTeam = @P496)) 
            AND (Task.OwnerTeam = @P497)) 
            AND (Task.OwnerTeam = @P498)) 
            AND (Task.OwnerTeam = @P499)) 
            AND (Task.OwnerTeam = @P500)) 
            AND (Task.OwnerTeam = @P501)) 
            AND (Task.OwnerTeam = @P502)) 
            AND (Task.OwnerTeam = @P503)) 
            AND (Task.OwnerTeam = @P504)) 
            AND (Task.OwnerTeam = @P505)) 
            AND (Task.OwnerTeam = @P506)) 
            AND (Task.OwnerTeam = @P507)) 
            AND (Task.OwnerTeam = @P508)) 
            AND (Task.OwnerTeam = @P509)) 
            AND (Task.OwnerTeam = @P510)) 
            AND (Task.OwnerTeam = @P511)) 
            AND (Task.OwnerTeam = @P512)) 
            AND (Task.OwnerTeam = @P513)))

我不得不承认,这个嵌套真是TMD太深了。

[英文原文:SQL Error 191: Nested Way Too F#%&ing Deeply ]
分享这篇文章:

12 Responses to 编程趣事:SQL Error 191

  1. julio says:

    哈哈,他有意思了,谁写的这个查询真NB!!

  2. superDeng says:

    这个查询语句真牛13

  3. halida says:

    没有办法呀,只能这样写.

  4. cyler123 says:

    啊,不必每件事情都通过SQL做的,适当变通啊,亲

  5. Scarecrow says:

    不过这也说明了SQL Server 代码写得很严谨,这种嵌套过多的异常都考虑到了

  6. 明明 对这篇文章的反应是俺的神呀
  7. mstop says:

    曾经也见DBA写过这样”牛”逼的东东.当时我觉得很生气. 只要是DBA都知道,无论什么语句,都不能超过32层.这个并不是象楼主说的”没有标准上限的错误”.
    修改的方法很简单.
    CREAVE VIEW VEW_Task AS
    SELECT 1 AS OwnerTeam
    UNION ALL
    SELECT 2
    UNION ALL
    SELECT 3
    ……

    GO
    SELECT DISTINCT COUNT(Task.RecId)
    FROM Task
    WHERE (Task.TaskType = @P514)
    AND (Task.Status = @P1)
    AND (Task.RecId is not null)
    AND EXISTS( SELECT 1 FROM VEW_Task WHERE OwnerTeam =Task.OwnerTeam )

  8. book523 says:

    sql有问题吧,全是and,p2-p513除非全相等才能有记录。而且全是and,

  9. 左方 对这篇文章的反应是俺的神呀
  10. 1827566828 对这篇文章的反应是俺的神呀
  11. fei says:

    (Task.OwnerTeam = @P2)
    AND (Task.OwnerTeam = @P3)
    这个明显是调戏大家的节凑啊!
    Task.OwnerTeam的值,要求 = @P2 and =@P3 and =@P4。

发表评论

邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据