设想一个SQL如果查询:

长腿爸爸 2010-05-06 10:28:01
一张表为新闻表(News)有10个短字段,2个非常长的内容字段。
页面列表中只显示10个短字段,这个SQL通常都是select n.Id,n.Name,..... from News n,不包括两个长字段,这样的SQL句子很长,有没有可以反过来写的,就是查询全部但不包括那两个长的字段。怎么实现?
...全文
125 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
喜-喜 2010-05-06
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 jaylianyu 的回复:]
引用 5 楼 fredrickhu 的回复:

根本就没必要这么写 除非你的字段很多


找这个方法,当然是字段很多的时候用。
可以写成个函数,那么以后不就方面很多。
[/Quote]

写成个函数!

那就用 3 楼的思路啊!
长腿爸爸 2010-05-06
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 fredrickhu 的回复:]

根本就没必要这么写 除非你的字段很多
[/Quote]

找这个方法,当然是字段很多的时候用。
可以写成个函数,那么以后不就方面很多。
长腿爸爸 2010-05-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 htl258 的回复:]

SQL code
declare @s varchar(8000)
select @s=isnull(@s+',','')+quotename(name) from syscolumns where id=object_id('news') and name not in('长字段1','长字段2')
exec('select '+@s+' from news')

[/Quote]

呵呵,这种方法真的存在。
上面的语句SQLServer数据库通过,遗憾的是我用的MySql数据库,还是用不上。
--小F-- 2010-05-06
  • 打赏
  • 举报
回复
根本就没必要这么写 除非你的字段很多
fred_guo_xf 2010-05-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 htl258 的回复:]
SQL code
declare @s varchar(8000)
select @s=isnull(@s+',','')+quotename(name) from syscolumns where id=object_id('news') and name not in('长字段1','长字段2')
exec('select '+@s+' from news')
[/Quote]

^_^
htl258_Tony 2010-05-06
  • 打赏
  • 举报
回复
declare @s varchar(8000)
select @s=isnull(@s+',','')+quotename(name) from syscolumns where id=object_id('news') and name not in('长字段1','长字段2')
exec('select '+@s+' from news')
水族杰纶 2010-05-06
  • 打赏
  • 举报
回复
一个一个写吧
动态语句 查系统表可以实现
貌似这样也没用
动态出来也写完了
chuifengde 2010-05-06
  • 打赏
  • 举报
回复
没有,除非有必要就动态构造,一般就一个一个写

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧