表a:TYPE C20 C40 COTH CNO CWT
整箱 1 2 4 56 45000
散货 0 0 0 44 6780得到:整箱,则 1xC20,2xC40,4xCOTH
散货,则 44件,6780公斤
整箱 1 2 4 56 45000
散货 0 0 0 44 6780得到:整箱,则 1xC20,2xC40,4xCOTH
散货,则 44件,6780公斤
解决方案 »
- 跨服务器为何不可以使用 with (nolock)?
- 急问一条SQL语句运行出错???
- 这样的重复记录如何处理
- 执行的连接字符串出错,求解.
- ALTER DATABASE pubs SET RECOVERY SIMPLE 有什么用?
- 求教oracle存储翻译成sqlserver存储
- 请问如何监控数据库中表数据的变化
- 如何把多个查询的结果自动导出到excel的不同sheet中?
- 紧急求助! 我想在一个子过程中返回一个长字符串到调用过程中如何处理? 用return 只能返回数值? 不行! 用参数@ret_string OUTPUT 可能行! 但忘了怎幺做! 哪位高手给我一个例子, 200分送上. 先谢谢啦!!!! 急用.
- 有没有人试过用ACCESS做网站数据库,效果如何?
- 存储过程!!!
- SQL要怎么改呀????
--这样?
--> 测试数据: [A]
if object_id('[A]') is not null drop table [A]
create table [A] (TYPE varchar(4),C20 int,C40 int,COTH int,CNO int,CWT int)
insert into [A]
select '整箱',1,2,4,56,45000 union all
select '散货',0,0,0,44,6780select type,des=
case C20 when 0 then ltrim(CNO)+'件,'+ltrim(Cwt)+'公斤'
else ltrim(c20)+'xC20,'+ltrim(C40)+'xC40,'+ltrim(COTH)+'xCOTH,' end
from [A]
select type ,c20=case type when '整箱' then cast(c20 as varchar)+'*C20' else '0' end,
c40=case type when '整箱' then cast(c40 as varchar)+'*C20' else '0' end,
coth=case type when '整箱' then cast(coth as varchar)+'*C20' else '0' end,
cno=case type when '散货' then cno else '0' end,
cwt=case type when '散货' then cwt else '0' end
from tb
整箱 1*C20 2*C20 4*C20 0 0
散货 0 0 0 44 6780
这样?
1xC20,2xC40,4xCOTH
44件,6780公斤
--> --> (让你望见影子的墙)生成測試數據
if not object_id('tb') is null
drop table tb
Go
Create table tb([TYPE] nvarchar(2),[C20] int,[C40] int,[COTH] int,[CNO] int,[CWT] int)
Insert tb
select N'整箱',1,2,4,56,45000 union all
select N'散货',0,0,0,44,6780
Go
Select * from tbselect type,显示=case type when '整箱' then cast(c20 as varchar)+'*C20,' +cast(c40 as varchar)+'*C20,' +cast(coth as varchar)+'*C20'
when '散货' then cast(cno as varchar)+'件,'+cast(cwt as varchar) +'公斤'else '0'
end
from tb
整箱 1*C20,2*C20,4*C20
散货 44件,6780公斤这样?
SELECT 显示= CASE WHEN TYPE='整箱' THEN
COL_NAME(OBJECT_ID('你的数据库名称.表a'), 2)+'x'+RTRIM(CAST(C20 AS VARCHAR(10)))+','
+COL_NAME(OBJECT_ID('你的数据库名称.表a'), 3)+'x'+ RTRIM(CAST(C40 AS VARCHAR(10)))+','
+COL_NAME(OBJECT_ID('你的数据库名称.表a'), 4)+'x'+ RTRIM(CAST(COTH AS VARCHAR(10)))
WHEN TYPE='散货' THEN RTRIM(CAST(CNO AS VARCHAR(10)))+'件'+','
+RTRIM(CAST(CWT AS VARCHAR(10))) +'公斤'
ELSE '' END
FROM 表a
最后把 ‘显示‘ 这个字段绑定在 Gridview 上。