日期:2014-05-18  浏览次数:20494 次

问一个菜鸟问题
有两条SQL语句:
select count(*) as num from dbo.tb
select create_date from sys.objects where object_id=object_id('tb')

显示结果是分开的,现在我希望这样同时显示:
  num create_date
  300 2012-04-15
 
怎么解决呢?
  




------解决方案--------------------
select count(*),(select create_date from sys.objects where object_id=object_id('tb')) as num from dbo.tb

------解决方案--------------------
SQL code
SELECT  COUNT(*) AS num ,
        ( SELECT    create_date
          FROM      sys.objects
          WHERE     object_id = OBJECT_ID('tb')
        ) AS 'create_date'
FROM    dbo.tb
SELECT  create_date
FROM    sys.objects
WHERE   object_id = OBJECT_ID('tb')

------解决方案--------------------
等价的写法,
SQL code

 select b.rowcnt as 'num',a.create_date
 from sys.objects a
 inner join sys.sysindexes b
 on a.[object_id]=b.id and b.indid=1
 where a.[object_id]=object_id('tb')