(SELECT TOP 1 ISNULL(XH,'NULL') AS XH FROM V_XSDM WHERE LEN(XH)=(SELECT ISNULL(MAX(LEN(XH)),0) FROM V_XSDM)) AS XH,
(SELECT TOP 1 ISNULL(XM,'NULL') AS XM FROM V_XSDM WHERE LEN(XM)=(SELECT ISNULL(MAX(LEN(XM)),0) FROM V_XSDM)) AS XM,
(SELECT TOP 1 ISNULL(XB,'NULL') AS XB FROM V_XSDM WHERE LEN(XB)=(SELECT ISNULL(MAX(LEN(XB)),0) FROM V_XSDM)) AS XB,
(SELECT TOP 1 ISNULL(ZJM,'NULL') AS ZJM FROM V_XSDM WHERE LEN(ZJM)=(SELECT ISNULL(MAX(LEN(ZJM)),0) FROM V_XSDM)) AS ZJM,
(SELECT TOP 1 ISNULL(RXND,'NULL') AS RXND FROM V_XSDM WHERE LEN(RXND)=(SELECT ISNULL(MAX(LEN(RXND)),0) FROM V_XSDM)) AS RXND,
(SELECT TOP 1 ISNULL(LXND,'NULL') AS LXND FROM V_XSDM WHERE LEN(LXND)=(SELECT ISNULL(MAX(LEN(LXND)),0) FROM V_XSDM)) AS LXND,
(SELECT TOP 1 ISNULL(BMDM,'NULL') AS BMDM FROM V_XSDM WHERE LEN(BMDM)=(SELECT ISNULL(MAX(LEN(BMDM)),0) FROM V_XSDM)) AS BMDM,
(SELECT TOP 1 ISNULL(BMMC,'NULL') AS BMMC FROM V_XSDM WHERE LEN(BMMC)=(SELECT ISNULL(MAX(LEN(BMMC)),0) FROM V_XSDM)) AS BMMC,
(SELECT TOP 1 ISNULL(ZYDM,'NULL') AS ZYDM FROM V_XSDM WHERE LEN(ZYDM)=(SELECT ISNULL(MAX(LEN(ZYDM)),0) FROM V_XSDM)) AS ZYDM,
(SELECT TOP 1 ISNULL(ZYMC,'NULL') AS ZYMC FROM V_XSDM WHERE LEN(ZYMC)=(SELECT ISNULL(MAX(LEN(ZYMC)),0) FROM V_XSDM)) AS ZYMC,
(SELECT TOP 1 ISNULL(BJDM,'NULL') AS BJDM FROM V_XSDM WHERE LEN(BJDM)=(SELECT ISNULL(MAX(LEN(BJDM)),0) FROM V_XSDM)) AS BJDM,
(SELECT TOP 1 ISNULL(BJMC,'NULL') AS BJMC FROM V_XSDM WHERE LEN(BJMC)=(SELECT ISNULL(MAX(LEN(BJMC)),0) FROM V_XSDM)) AS BJMC,
(SELECT TOP 1 ISNULL(XSXZDM,'NULL') AS XSXZDM FROM V_XSDM WHERE LEN(XSXZDM)=(SELECT ISNULL(MAX(LEN(XSXZDM)),0) FROM V_XSDM)) AS XSXZDM,
(SELECT TOP 1 ISNULL(XSXZMC,'NULL') AS XSXZMC FROM V_XSDM WHERE LEN(XSXZMC)=(SELECT ISNULL(MAX(LEN(XSXZMC)),0) FROM V_XSDM)) AS XSXZMC,
(SELECT TOP 1 ISNULL(XSLYDM,'NULL') AS XSLYDM FROM V_XSDM WHERE LEN(XSLYDM)=(SELECT ISNULL(MAX(LEN(XSLYDM)),0) FROM V_XSDM)) AS XSLYDM,
(SELECT TOP 1 ISNULL(XSLYMC,'NULL') AS XSLYMC FROM V_XSDM WHERE LEN(XSLYMC)=(SELECT ISNULL(MAX(LEN(XSLYMC)),0) FROM V_XSDM)) AS XSLYMC,
(SELECT TOP 1 ISNULL(XSZTDM,'NULL') AS XSZTDM FROM V_XSDM WHERE LEN(XSZTDM)=(SELECT ISNULL(MAX(LEN(XSZTDM)),0) FROM V_XSDM)) AS XSZTDM,
(SELECT TOP 1 ISNULL(CSRQ,'NULL') AS CSRQ FROM V_XSDM WHERE LEN(CSRQ)=(SELECT ISNULL(MAX(LEN(CSRQ)),0) FROM V_XSDM)) AS CSRQ,
(SELECT TOP 1 ISNULL(JTZZ,'NULL') AS JTZZ FROM V_XSDM WHERE LEN(JTZZ)=(SELECT ISNULL(MAX(LEN(JTZZ)),0) FROM V_XSDM)) AS JTZZ,
(SELECT TOP 1 ISNULL(SFZH,'NULL') AS SFZH FROM V_XSDM WHERE LEN(SFZH)=(SELECT ISNULL(MAX(LEN(SFZH)),0) FROM V_XSDM)) AS SFZH,
(SELECT TOP 1 ISNULL(YHZH,'NULL') AS YHZH FROM V_XSDM WHERE LEN(YHZH)=(SELECT ISNULL(MAX(LEN(YHZH)),0) FROM V_XSDM)) AS YHZH,
(SELECT TOP 1 ISNULL(ICKH,'NULL') AS ICKH FROM V_XSDM WHERE LEN(ICKH)=(SELECT ISNULL(MAX(LEN(ICKH)),0) FROM V_XSDM)) AS ICKH,
(SELECT TOP 1 ISNULL(BZ,'NULL') AS BZ FROM V_XSDM WHERE LEN(BZ)=(SELECT ISNULL(MAX(LEN(BZ)),0) FROM V_XSDM)) AS BZ,
(SELECT TOP 1 ISNULL(SFYX,'NULL') AS SFYX FROM V_XSDM WHERE LEN(SFYX)=(SELECT ISNULL(MAX(LEN(SFYX)),0) FROM V_XSDM)) AS SFYX
From V_XSDM
服务器: 消息 4414,级别 16,状态 1,行 1
未能为视图或函数解析分配辅助表。超过了查询中表的最大数目(260)。
好象没有超过260个查询啊?这是怎么回事?
4 个解决方案
#1
Create Procedure GETCOLWIDTH
@Table VarChar(20)
AS
Begin Transaction
SET NOCOUNT ON
Declare @tCol VarChar(20),@Cols VarChar(8000),@SQL VarChar(8000)
Declare Col Cursor for Select name From dbo.syscolumns Where id=(Select id From dbo.sysobjects Where name=@Table)
Open Col
Fetch Next From Col Into @tCol
Set @Cols='(SELECT TOP 1 ISNULL(' + @tCol + ',''NULL'') AS ' + @tCol + ' FROM ' + @Table + ' WHERE LEN(' + @tCol + ')=(SELECT ISNULL(MAX(LEN(' + @tCol + ')),0) FROM ' + @Table + ')) AS ' + @tCol
While @@FETCH_STATUS=0
Begin
Fetch Next From Col Into @tCol
IF @@FETCH_STATUS=0
Set @Cols=@Cols + ',(SELECT TOP 1 ISNULL(' + @tCol + ',''NULL'') AS ' + @tCol + ' FROM ' + @Table + ' WHERE LEN(' + @tCol + ')=(SELECT ISNULL(MAX(LEN(' + @tCol + ')),0) FROM ' + @Table + ')) AS ' + @tCol
End
Close Col
DealLocate Col
Set @SQL='Select Top 1 ' + @Cols + ' From ' + @Table
EXEC(@SQL)
SET NOCOUNT OFF
Commit Transaction
If @@error<>0
Rollback Transaction
return @@error
GO
以上查询是通过这个存储过程得到的,只是想得到一个统计表中每列最长字符的结果集。
有没有什么办法解决呢?
@Table VarChar(20)
AS
Begin Transaction
SET NOCOUNT ON
Declare @tCol VarChar(20),@Cols VarChar(8000),@SQL VarChar(8000)
Declare Col Cursor for Select name From dbo.syscolumns Where id=(Select id From dbo.sysobjects Where name=@Table)
Open Col
Fetch Next From Col Into @tCol
Set @Cols='(SELECT TOP 1 ISNULL(' + @tCol + ',''NULL'') AS ' + @tCol + ' FROM ' + @Table + ' WHERE LEN(' + @tCol + ')=(SELECT ISNULL(MAX(LEN(' + @tCol + ')),0) FROM ' + @Table + ')) AS ' + @tCol
While @@FETCH_STATUS=0
Begin
Fetch Next From Col Into @tCol
IF @@FETCH_STATUS=0
Set @Cols=@Cols + ',(SELECT TOP 1 ISNULL(' + @tCol + ',''NULL'') AS ' + @tCol + ' FROM ' + @Table + ' WHERE LEN(' + @tCol + ')=(SELECT ISNULL(MAX(LEN(' + @tCol + ')),0) FROM ' + @Table + ')) AS ' + @tCol
End
Close Col
DealLocate Col
Set @SQL='Select Top 1 ' + @Cols + ' From ' + @Table
EXEC(@SQL)
SET NOCOUNT OFF
Commit Transaction
If @@error<>0
Rollback Transaction
return @@error
GO
以上查询是通过这个存储过程得到的,只是想得到一个统计表中每列最长字符的结果集。
有没有什么办法解决呢?
#2
顶一下
#3
#4
try:
Create Procedure GETCOLWIDTH
@Table VarChar(20)
AS
Begin Transaction
SET NOCOUNT ON
Declare @tCol VarChar(20),@Cols VarChar(8000),@SQL VarChar(8000)
Declare Col Cursor for Select name From dbo.syscolumns Where id=(Select id From dbo.sysobjects Where name=@Table)
Open Col
Fetch Next From Col Into @tCol
Set @Cols='(SELECT TOP 1 ISNULL(' + @tCol + ',''NULL'') AS ' + @tCol + ' FROM ' + @Table + ' WHERE LEN(' + @tCol + ')=(SELECT ISNULL(MAX(LEN(' + @tCol + ')),0) FROM ' + @Table + ')) AS ' + @tCol
While @@FETCH_STATUS=0
Begin
Fetch Next From Col Into @tCol
IF @@FETCH_STATUS=0
Set @Cols=@Cols + ',(SELECT TOP 1 ISNULL(' + @tCol + ',''NULL'') AS ' + @tCol + ' FROM ' + @Table + ' WHERE LEN(' + @tCol + ')=(SELECT ISNULL(MAX(LEN(' + @tCol + ')),0) FROM ' + @Table + ')) AS ' + @tCol
End
Close Col
DealLocate Col
Set @SQL='Select ' + @Cols
EXEC(@SQL)
SET NOCOUNT OFF
Commit Transaction
If @@error<>0
Rollback Transaction
return @@error
GO
--好像每个字段都少了order by子句
#1
Create Procedure GETCOLWIDTH
@Table VarChar(20)
AS
Begin Transaction
SET NOCOUNT ON
Declare @tCol VarChar(20),@Cols VarChar(8000),@SQL VarChar(8000)
Declare Col Cursor for Select name From dbo.syscolumns Where id=(Select id From dbo.sysobjects Where name=@Table)
Open Col
Fetch Next From Col Into @tCol
Set @Cols='(SELECT TOP 1 ISNULL(' + @tCol + ',''NULL'') AS ' + @tCol + ' FROM ' + @Table + ' WHERE LEN(' + @tCol + ')=(SELECT ISNULL(MAX(LEN(' + @tCol + ')),0) FROM ' + @Table + ')) AS ' + @tCol
While @@FETCH_STATUS=0
Begin
Fetch Next From Col Into @tCol
IF @@FETCH_STATUS=0
Set @Cols=@Cols + ',(SELECT TOP 1 ISNULL(' + @tCol + ',''NULL'') AS ' + @tCol + ' FROM ' + @Table + ' WHERE LEN(' + @tCol + ')=(SELECT ISNULL(MAX(LEN(' + @tCol + ')),0) FROM ' + @Table + ')) AS ' + @tCol
End
Close Col
DealLocate Col
Set @SQL='Select Top 1 ' + @Cols + ' From ' + @Table
EXEC(@SQL)
SET NOCOUNT OFF
Commit Transaction
If @@error<>0
Rollback Transaction
return @@error
GO
以上查询是通过这个存储过程得到的,只是想得到一个统计表中每列最长字符的结果集。
有没有什么办法解决呢?
@Table VarChar(20)
AS
Begin Transaction
SET NOCOUNT ON
Declare @tCol VarChar(20),@Cols VarChar(8000),@SQL VarChar(8000)
Declare Col Cursor for Select name From dbo.syscolumns Where id=(Select id From dbo.sysobjects Where name=@Table)
Open Col
Fetch Next From Col Into @tCol
Set @Cols='(SELECT TOP 1 ISNULL(' + @tCol + ',''NULL'') AS ' + @tCol + ' FROM ' + @Table + ' WHERE LEN(' + @tCol + ')=(SELECT ISNULL(MAX(LEN(' + @tCol + ')),0) FROM ' + @Table + ')) AS ' + @tCol
While @@FETCH_STATUS=0
Begin
Fetch Next From Col Into @tCol
IF @@FETCH_STATUS=0
Set @Cols=@Cols + ',(SELECT TOP 1 ISNULL(' + @tCol + ',''NULL'') AS ' + @tCol + ' FROM ' + @Table + ' WHERE LEN(' + @tCol + ')=(SELECT ISNULL(MAX(LEN(' + @tCol + ')),0) FROM ' + @Table + ')) AS ' + @tCol
End
Close Col
DealLocate Col
Set @SQL='Select Top 1 ' + @Cols + ' From ' + @Table
EXEC(@SQL)
SET NOCOUNT OFF
Commit Transaction
If @@error<>0
Rollback Transaction
return @@error
GO
以上查询是通过这个存储过程得到的,只是想得到一个统计表中每列最长字符的结果集。
有没有什么办法解决呢?
#2
顶一下
#3
#4
try:
Create Procedure GETCOLWIDTH
@Table VarChar(20)
AS
Begin Transaction
SET NOCOUNT ON
Declare @tCol VarChar(20),@Cols VarChar(8000),@SQL VarChar(8000)
Declare Col Cursor for Select name From dbo.syscolumns Where id=(Select id From dbo.sysobjects Where name=@Table)
Open Col
Fetch Next From Col Into @tCol
Set @Cols='(SELECT TOP 1 ISNULL(' + @tCol + ',''NULL'') AS ' + @tCol + ' FROM ' + @Table + ' WHERE LEN(' + @tCol + ')=(SELECT ISNULL(MAX(LEN(' + @tCol + ')),0) FROM ' + @Table + ')) AS ' + @tCol
While @@FETCH_STATUS=0
Begin
Fetch Next From Col Into @tCol
IF @@FETCH_STATUS=0
Set @Cols=@Cols + ',(SELECT TOP 1 ISNULL(' + @tCol + ',''NULL'') AS ' + @tCol + ' FROM ' + @Table + ' WHERE LEN(' + @tCol + ')=(SELECT ISNULL(MAX(LEN(' + @tCol + ')),0) FROM ' + @Table + ')) AS ' + @tCol
End
Close Col
DealLocate Col
Set @SQL='Select ' + @Cols
EXEC(@SQL)
SET NOCOUNT OFF
Commit Transaction
If @@error<>0
Rollback Transaction
return @@error
GO
--好像每个字段都少了order by子句