这样的SQL语法写的很烂,大家看看怎么写漂亮一点

musicboywq 2006-09-18 04:51:43
两张表wl_purorderh和gg_itemcode,要将wl_purorderh表里的unitid替换为gg_itemcode的unitid,替换条件是
gg_itemcode.itemcode=wl_purorderh.itemcode




我写的如下:
update wl_purorderh
set wl_purorderh.unitid=gg_itemcode.unitid
from wl_purorderh,gg_itemcode
where gg_itemcode.itemcode=wl_purorderh.itemcode

今天被别人笑了,看看大家还有别的什么写法比较好。能更漂亮一点!!
...全文
320 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
依然白板 2006-09-19
  • 打赏
  • 举报
回复
不过是没用简称`````

这句法又没错误,有什么可笑的```

给你一块板砖,去把笑你的人拍死吧```
hacky912 2006-09-19
  • 打赏
  • 举报
回复
自己的风格,是对的就是好的啦
lzuyh 2006-09-19
  • 打赏
  • 举报
回复
楼主没错
musicboywq 2006-09-19
  • 打赏
  • 举报
回复
libin_ftsafe(子陌红尘:当libin告别ftsafe)


update wl_purorderh w (这个W查询分析的时候老报错)
set
unitid=g.unitid
from
gg_itemcode g
where
w.itemcode=g.itemcode


感觉子陌红尘这个好象有错的!
colhunt 2006-09-19
  • 打赏
  • 举报
回复
我觉得楼主没错
Well 2006-09-18
  • 打赏
  • 举报
回复
我写的如下:
update WL
set WL.unitid=GG.unitid
from wl_purorderh WL,gg_itemcode GG
where GG.itemcode=WL.itemcode

不过在写编码的时,只要有自己的的风格也行。自己固定的格式。
dawugui 2006-09-18
  • 打赏
  • 举报
回复
楼主的做法有何不妥?
wgqqgw 2006-09-18
  • 打赏
  • 举报
回复
楼主的写法有什么可笑之处呢?

我想知道上面的各种和楼主不一样的写法,效率是否都是一样的?
lalakid 2006-09-18
  • 打赏
  • 举报
回复
create procedure sp_lock --- 1996/04/08 00:00
@spid1 int = NULL, /* server process id to check for locks */
@spid2 int = NULL /* other process id to check for locks */
as

set nocount on
/*
** Show the locks for both parameters.
*/
if @spid1 is not NULL
begin
select convert (smallint, req_spid) As spid,
rsc_dbid As dbid,
rsc_objid As ObjId,
rsc_indid As IndId,
substring (v.name, 1, 4) As Type,
substring (rsc_text, 1, 16) as Resource,
substring (u.name, 1, 8) As Mode,
substring (x.name, 1, 5) As Status

from master.dbo.syslockinfo,
master.dbo.spt_values v,
master.dbo.spt_values x,
master.dbo.spt_values u

where master.dbo.syslockinfo.rsc_type = v.number
and v.type = 'LR'
and master.dbo.syslockinfo.req_status = x.number
and x.type = 'LS'
and master.dbo.syslockinfo.req_mode + 1 = u.number
and u.type = 'L'

and req_spid in (@spid1, @spid2)
end

/*
** No parameters, so show all the locks.
*/
else
begin
select convert (smallint, req_spid) As spid,
rsc_dbid As dbid,
rsc_objid As ObjId,
rsc_indid As IndId,
substring (v.name, 1, 4) As Type,
substring (rsc_text, 1, 16) as Resource,
substring (u.name, 1, 8) As Mode,
substring (x.name, 1, 5) As Status

from master.dbo.syslockinfo,
master.dbo.spt_values v,
master.dbo.spt_values x,
master.dbo.spt_values u

where master.dbo.syslockinfo.rsc_type = v.number
and v.type = 'LR'
and master.dbo.syslockinfo.req_status = x.number
and x.type = 'LS'
and master.dbo.syslockinfo.req_mode + 1 = u.number
and u.type = 'L'
order by spid
end

return (0) -- sp_lock
lalakid 2006-09-18
  • 打赏
  • 举报
回复
看帮助文档里的例子是怎么写的,
另外,有很多系统存储过程,你可以参考他们的写法
如:想看系统存储过程SP_LOCK是怎么写的,可以在查询分析器里如下写:
SP_HELPTEXT SP_LOCK
---------------------------------
把结果集复制粘贴就可以看了
zsforever 2006-09-18
  • 打赏
  • 举报
回复
update wl_purorderh w
set
unitid=g.unitid
from
gg_itemcode g
where
w.itemcode=g.itemcode
注意,这样的句法是错误的,要用别名要在From 后加才可以
ljjable 2006-09-18
  • 打赏
  • 举报
回复
update wl_purorderh w
set
unitid=g.unitid
from
gg_itemcode g
where
w.itemcode=g.itemcode
zsforever 2006-09-18
  • 打赏
  • 举报
回复
update wl_purorderh
set
unitid=g.unitid
from
gg_itemcode g
where
wl_purorderh.itemcode=g.itemcode
子陌红尘 2006-09-18
  • 打赏
  • 举报
回复
update wl_purorderh w
set
unitid=g.unitid
from
gg_itemcode g
where
w.itemcode=g.itemcode

34,594

社区成员

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

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