求SQL语句 关于数据字典功能的

wang520d 2008-03-31 09:44:42
字典表 DataDict的字段如下
tablename cloName colNote conShow conSort
t_product_list listID 产品标识 1 2
t_product_list pname 产品名称 1 1
t_product_list ptype 产品类型 0 3
t_product_list psource 产品来源 0 4
t_user userid 用户标识 1 1
t_user username 用户名称 1 2
t_user userage 用户年龄 1 3
t_user usersex 用户性别 0 4


产品表如下 t_product_list
listid pname ptype psource
1 茶叶 日用品 仓库一
2 鞋子 日用品 仓库二
3 帽子 日用品 仓库三

我想根据字典表中字段conshow取产品表t_product_list的记录(取conshow=1)同事将产品表t_product_list的字段名按照字典表中的字段colNote进行翻译
并按照排序字段consort进行排序显示得到如下结果:

产品名称 产品标识
茶叶 1
鞋子 2
帽子 3


...全文
557 29 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
f12014 2008-04-02
  • 打赏
  • 举报
回复
收下 支持
wang520d 2008-04-01
  • 打赏
  • 举报
回复
[Quote=引用 25 楼 dawugui 的回复:]
引用 17 楼 dawugui 的回复:
SQL code
--我没看懂你的意思,把试试下面这个:
declare @sql varchar(1000)
set @sql=''
select @sql=@sql+',['+colnote+']='+cloname --这里加了[]符号,看有没有效果?
from datadict where tablename='t_product_list' and conshow=1
set @sql='select '+stuff(@sql,1,1,'')+' from t_product_list'
print @sql --加个显示动态SQL,看看什么地方出错?
exec(@sql)


我在17楼就…
[/Quote]

我倒 真惭愧。。
问题搞定 结贴。。
colorli 2008-04-01
  • 打赏
  • 举报
回复
有点复杂!
changjiangzhibin 2008-04-01
  • 打赏
  • 举报
回复
路过
dawugui 2008-03-31
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 dawugui 的回复:]
SQL code
--我没看懂你的意思,把试试下面这个:
declare @sql varchar(1000)
set @sql=''
select @sql=@sql+',['+colnote+']='+cloname --这里加了[]符号,看有没有效果?
from datadict where tablename='t_product_list' and conshow=1
set @sql='select '+stuff(@sql,1,1,'')+' from t_product_list'
print @sql --加个显示动态SQL,看看什么地方出错?
exec(@sql)
[/Quote]

我在17楼就告诉你了,加[]符号.
wang520d 2008-03-31
  • 打赏
  • 举报
回复
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: '(' 附近有语法错误。

select 产品说明=ProductDesc,产品库存数量=StoreNumber,仓库=StoreRoomID,推荐类型=CommendTypeID,产品小类=SmallTypeID,产品来源=ProductSourceID,PV值=PV,BV值=BV,产品大类=TypeID,产品描述=Description,报警数量=AlarmNumber,产品适用人群ID(对应表ProductApplyPeople)=ProductApplyPeopleID,产品形态ID(对应表ProductForm)=ProductFormID,产品重量=ProductWeight,产品颜色ID号(对应表ProductColor)=ProductColorID,产品尺寸ID(对应表ProductSize)=ProductSizeID,产地=ProductArea,单位数量=UnitNumber,小单位(对应ProductUnit表)=SmallUnitID,大单位ID(对应表ProductUnit)=BigUnitID,优惠价格积分=ActressPriceIntegral,普通价格积分=CommonPriceIntegal,会员价格=ActressPrice,市场价格=CommonPrice,成本价格=CostPrice,产品规格ID(与产品规格表ProductSpecs对应)=ProductSpecsID,产品型号=ProductCode,是否组合产品(1是,0不是)=IsTeam,产品名称=ProductName from t_product_list


怎么处理字段中文描述中出现特殊字符????
wang520d 2008-03-31
  • 打赏
  • 举报
回复
第 1 行: '、' 附近有语法错误。
select 产品标识=listid,1文本框类型、2下拉框=pname from t_product_list
wang520d 2008-03-31
  • 打赏
  • 举报
回复
就是不认这个"、"顿号
wang520d 2008-03-31
  • 打赏
  • 举报
回复
哈哈终于找到原因了

insert into datadict select 't_product_list','pname','产品名称',1,1


把这条记录的“产品名称”改为 “1文本框类型、2下拉框”
再用这个语句就会报错

declare @sql varchar(8000)
set @sql=''
select @sql=@sql+','+colnote+'='+cloname
from datadict where tablename='t_product_list' and conshow=1 order by consort desc
set @sql='select '+stuff(@sql,1,1,'')+' from t_product_list'
exec(@sql)



怎么修改呢?
-狙击手- 2008-03-31
  • 打赏
  • 举报
回复
太长,洗澡
dawugui 2008-03-31
  • 打赏
  • 举报
回复
print @sql
然后把这个结果帖出来.
wang520d 2008-03-31
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 iamme81 的回复:]
引用 5 楼 wang520d 的回复:
declare @sql varchar(1000)
set @sql=''
select @sql=@sql+','+colnote+'='+colname
from datadict where tablename='t_product_list' and conshow=1 order by consort
set @sql='select '+stuff(@sql,1,1,'')+' from t_product_list'
exec(@sql)

郁闷我把你的语句用到我真实的表上面报错了
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: '是' 附近有语法错误。

[/Quote]

=======没有啊。。。这还能看错啊。。。。郁闷啊。。。到底哪里出问题了
可能跟我的真实表中的记录有关系。。我感觉。
dawugui 2008-03-31
  • 打赏
  • 举报
回复

--我没看懂你的意思,把试试下面这个:
declare @sql varchar(1000)
set @sql=''
select @sql=@sql+',['+colnote+']='+cloname --这里加了[]符号,看有没有效果?
from datadict where tablename='t_product_list' and conshow=1
set @sql='select '+stuff(@sql,1,1,'')+' from t_product_list'
print @sql --加个显示动态SQL,看看什么地方出错?
exec(@sql)
wang520d 2008-03-31
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 cson_cson 的回复:]
SQL code
declare @tn varchar(50),@b int ,@e int,@sql varchar(1000)
select @tn = 't_product_list',@b= 1,@e = 2
select @sql = isnull(@sql+',','')+colnote+'='+cloname from datadict
where tablename = @tn and consort between @b and @e order by consort
set @sql = 'select '+@sql+' from '+@tn
exec(@sql)
[/Quote]

为什么换到我的字典表上用就报错呢 报的错跟上面那个朋友的一样
iamme81 2008-03-31
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wang520d 的回复:]
declare @sql varchar(1000)
set @sql=''
select @sql=@sql+','+colnote+'='+colname
from datadict where tablename='t_product_list' and conshow=1 order by consort
set @sql='select '+stuff(@sql,1,1,'')+' from t_product_list'
exec(@sql)

郁闷我把你的语句用到我真实的表上面报错了
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: '是' 附近有语法错误。

下面是我的表结构
if exists (sele…
[/Quote]
第一行附近哪有'是'这个汉字,你是不是在复制的时候多打了一个汉字?
cson_cson 2008-03-31
  • 打赏
  • 举报
回复

declare @tn varchar(50),@b int ,@e int,@sql varchar(1000)
select @tn = 't_product_list',@b= 1,@e = 2
select @sql = isnull(@sql+',','')+colnote+'='+cloname from datadict
where tablename = @tn and consort between @b and @e order by consort
set @sql = 'select '+@sql+' from '+@tn
exec(@sql)
wang520d 2008-03-31
  • 打赏
  • 举报
回复
产品标t_product_list 有四个字段 这四个字段的中文名都保存在datadic表里面。我现在想翻译t_product_list表的字段名为datadic表中定义的中文名
wang520d 2008-03-31
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 dawugui 的回复:]
引用 9 楼 wang520d 的回复:
引用 6 楼 dawugui 的回复:
我没看懂.


是哪里没看懂 是我的要求还是刚刚那个错误。

上面给出了我的字典表跟字典表里面的几个表结构的数据麻烦帮我写下SQL

是你的要求怎么得出的结果?
[/Quote]

==========
datadict字典表字段的意思
tablename(表示某个表的名字)colname(表示tablename字段中表的字段名)colnote(字段的中文意思) conshow(表示这个字段是否显示) conSort(表示字段的排序)
t_product_list listID 产品标识 1 2
t_product_list pname 产品名称 1 1
t_product_list ptype 产品类型 0 3
t_product_list psource 产品来源 0 4
t_user userid 用户标识 1 1
t_user username 用户名称 1 2
t_user userage 用户年龄 1 3
t_user usersex 用户性别 0 4


产品表如下 t_product_list (这个表的字段在datadict表的colname中都有定义)
listid pname ptype psource
1 茶叶 日用品 仓库一
2 鞋子 日用品 仓库二
3 帽子 日用品 仓库三
wang520d 2008-03-31
  • 打赏
  • 举报
回复
我的数据库是2000 是不是有字符串转译的问题啊。
dawugui 2008-03-31
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 wang520d 的回复:]
引用 6 楼 dawugui 的回复:
我没看懂.


是哪里没看懂 是我的要求还是刚刚那个错误。

上面给出了我的字典表跟字典表里面的几个表结构的数据麻烦帮我写下SQL
[/Quote]
是你的要求怎么得出的结果?
加载更多回复(9)

34,838

社区成员

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

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