English 中文(简体)
从表Q中显示栏标题和行文
原标题:Use jQuery to display column headings and rows from a SQL table

我正试图利用“ j”从KQES服务器桌上显示一栏和行号。

我从表1中选择了<代码>SlectT*>的表格,因此,我不知道栏标题是什么,除非我与<代码>sys.columns分开。 选定的说明中的产出也以打击特别安全局的XML格式列出。

我如何选择一栏

SELECT c.column_id, c.name, y.system_type_id, y.name AS system_type_name
FROM sys.columns AS c
JOIN sys.types AS y ON c.system_type_id = y.system_type_id
JOIN sys.tables AS t ON c.object_id = t.object_id
WHERE y.name NOT LIKE  sysname  
AND t.object_id =  1234567890 
FOR XML RAW, TYPE, ROOT( rows );

样本XML产出

<rows>
  <row column_id="1" name="id" system_type_id="56" system_type_name="int" />
  <row column_id="5" name="added" system_type_id="61" system_type_name="datetime" />
  <row column_id="4" name="allowlogin" system_type_id="104" system_type_name="bit" />
  <row column_id="3" name="pw" system_type_id="165" system_type_name="varbinary" />
  <row column_id="2" name="un" system_type_id="231" system_type_name="nvarchar" />
</rows>

我如何选择行文

SELECT * FROM table1 FOR XML RAW, TYPE, ROOT( rows )

我可以指出(或许是因为时间晚)如何做到这一点。 任何想法?

问题回答

如果我正确理解你的话,你就希望把一栏名字放在像实地1,菲尔德2,菲尔德3。

如果是这样的话,你可以这样做:

SELECT STUFF((SELECT  , +name FROM YourDatabaseName.sys.columns WHERE object_id = OBJECT_ID( YourTableName ) ORDER BY column_id FOR XML PATH(  )),1,1,  ) 

希望帮助!





相关问题
Performance impact of indexed view in MS SQL Server 2008

Does anyone have experience with using indexed view in MS SQL Server 2008? I am trying to find out how does indexed view affect performance of insert / update statements, that are adding / updating ...

Lock Escalation - What s happening here?

While altering a table (removing a column) in SQL Server 2008, I clicked the Generate Change Script button and I noticed that the change script it generated drops the column, says "go" and then runs ...

Round to nearest 5 in SQL Server

I have a Money column in my SQL Server 2008 table. In my below query how can I round it to nearest 5$ select FineAmount from tickets Thanks

热门标签