关键字 'order' 附近有语法错误。
view_sys_channel--存储过程名@Top varchar(100),
@strWhere varchar(250)
AS
BEGIN
exec('(SELECT top '+@Top+' article.id, along_article.[user_id], news.zhaiyao, diggs.digg_good FROM (article INNER JOIN news ON article.id = news.id)
INNER JOIN diggs ON article.id = diggs.id '+@strWhere+')')
END
exec view_sys_channel '10','where articel.id>0'--这样执行完全OK
exec view_sys_channel '10','where articel.id>0 order by n.id desc'或
exec view_sys_channel '10','order by n.id desc'都提示关键字 'order' 附近有语法错误。
哪们大虾帮我看看是怎么回事,我是新手,一切都靠自学,大家帮我一下吧 --------------------编程问答-------------------- n.id 哪里来的n? --------------------编程问答-------------------- 没见过这种写法 谁解释下
SELECT top '+@Top+' article.id, along_article.[user_id], news.zhaiyao, diggs.digg_good FROM (article INNER JOIN news ON article.id = news.id)
INNER JOIN diggs ON article.id = diggs.id '+@strWhere+') --------------------编程问答-------------------- 表名用错了?
order by news.id
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/ --------------------编程问答-------------------- 教你个方法。
(SELECT top '+@Top+' article.id, along_article.[user_id], news.zhaiyao, diggs.digg_good FROM (article INNER JOIN news ON article.id = news.id)
INNER JOIN diggs ON article.id = diggs.id '+@strWhere+')'
定义1个sql变量接收一下里面的sql语句,然后print @sql,最后再exec @sql。 --------------------编程问答-------------------- print @sql 出来后,再把这个sql语句带到数据库中执行一下,看看哪里语法错误了。 --------------------编程问答-------------------- 话说确实找不到n.id --------------------编程问答-------------------- 先把你的exec 改为print然后到查询分析器里看看最终的sql语句,就一目了然了。 --------------------编程问答-------------------- 那个n.id确实是我写错了,应该是news.id但也是同关的问题 --------------------编程问答-------------------- set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[view_article_news]
@shu int,
@strWhere varchar(100)
AS
BEGIN
declare @sqcac varchar(1000)
set @sqcac='(SELECT top '+rtrim(@shu)+' along_article.id, along_article.channel_id, along_article.category_id, along_article.title,
along_article.link_url, along_article.img_url, along_article.seo_title, along_article.seo_keywords,
along_article.seo_description, along_article.[content], along_article.sort_id, along_article.click, along_article.is_lock,
along_article.[user_id], along_article.add_time, along_article_news.author, along_article_news.[from], along_article_news.zhaiyao,
along_article_news.is_msg, along_article_news.is_top, along_article_news.is_red, along_article_news.is_hot, along_article_news.is_slide,
along_article_diggs.digg_good, along_article_diggs.digg_bad FROM (along_article INNER JOIN along_article_news ON along_article.id = along_article_news.id)
INNER JOIN along_article_diggs ON along_article.id = along_article_diggs.id '+@strWhere+')'
exec(@sqcac)
END
exec view_article_news 10,'where along_article_news.id>0 order by along_article_news.id desc'失败,帮我看看哪里写错了,问题就是ORDER附近有错误 把ORDER和后面的去掉就OK, --------------------编程问答-------------------- 我刚用了PRINT执行出来的是
(SELECT top 10 along_article.id, along_article.channel_id, along_article.category_id, along_article.title,
along_article.link_url, along_article.img_url, along_article.seo_title, along_article.seo_keywords,
along_article.seo_description, along_article.[content], along_article.sort_id, along_article.click, along_article.is_lock,
along_article.[user_id], along_article.add_time, along_article_news.author, along_article_news.[from], along_article_news.zhaiyao,
along_article_news.is_msg, along_article_news.is_top, along_article_news.is_red, along_article_news.is_hot, along_article_news.is_slide,
along_article_diggs.digg_good, along_article_diggs.digg_bad FROM (along_article INNER JOIN along_article_news ON along_article.id = along_article_news.id)
INNER JOIN along_article_diggs ON along_article.id = along_article_diggs.id where along_article_news.id>0 order by along_article_news.id desc)
消息 156,级别 15,状态 1,第 7 行
关键字 'order' 附近有语法错误。
我复制这代码执行不带有变量的话OK,我不知道问题出在哪里了,
--------------------编程问答-------------------- (SELECT top 10 along_article.id,
along_article.channel_id,
along_article.category_id,
along_article.title,
along_article.link_url,
along_article.img_url,
along_article.seo_title,
along_article.seo_keywords,
along_article.seo_description,
along_article.[content],
along_article.sort_id,
along_article.click,
along_article.is_lock,
along_article.[user_id],
along_article.add_time,
along_article_news.author,
along_article_news.[from],
along_article_news.zhaiyao,
along_article_news.is_msg,
along_article_news.is_top,
along_article_news.is_red,
along_article_news.is_hot,
along_article_news.is_slide,
along_article_diggs.digg_good,
along_article_diggs.digg_bad
FROM (select * from along_article INNER JOIN along_article_news ON along_article.id = along_article_news.id) as cINNER JOIN along_article_diggs ON along_article.id = along_article_diggs.id where along_article_news.id>0 order by c.id desc)
这样改下试试
补充:.NET技术 , C#