Sql问题

1.SELECT * FROM LeadView WHERE (PosId LIKE '00229') ORDER BY Id DESC

操作的字段名:IsLive(在职状态)

查询的结果:

在职状态   我现在想攺成  在职状态

T                      离职
F                              在职
解决方法SELECT *,
case 在职状态

when 'T' then '离职'

when 'F' then '在职'

when '' then ''
end 在职状态

FROM LeadView WHERE (PosId LIKE '00229') ORDER BY Id DESC

2.有关于传值到存储过程中,参数单引号的问题 [2006-06-16]
[解决方法如下]
/********************程序中要的代码段部分**********
declare @uid  varchar(50)
declare @Name varchar(200)   
declare @sql varchar(200)
//

select @uid ='test'
[关键部分]
以前我是这样写,但是出现问题,sql语句执行的结果为空
select @Name ='name1'+'name2'
因为net编译的问题,编译会自动进行其他操作,所以正确的写法应该改为
select @Name ='''name1'''+',''name2'''
********************程序中要的代码段部分**********/

/********************存储过程中要的部分**********
以前是这样写的
select * from formName where uid=@uid and name in(@Name)

现在正确写法
select @sql ='select * from formName where uid='''+@uid +''' and name in('+@Name+')'
exec (@sql)

为什么要用这样方式吗,是因为是sql是拼的,又因为是传值单引号的问题。
所以选用变量的方式来执行
如果需要用if exists(select*...)
建议不用是变量的方式来执行。
if exists (exec @sql)  --这样写是有问题的。切记!
如果有正确的 if exists写法,请跟帖。谢谢。
/********************存储过程中要的部分**********



A库.A表和B库.B表是同结构的表,
 
A库.A表有数据,
B库.B表无
 
我现在从A库.A表导出数据到B库.B表,
有一个错误:
 
An explicit value for the identity column in table ‘B库.B表' can only be specified when a column list is used and IDENTITY_INSERT is ON.
哪有错了?
 

Sql:
 
set IDENTITY_INSERT B库.B表 ON 
insert into B库.B表 select * from A库.A表
set IDENTITY_INSERT B库.B表 OFF

解决方案:
这个错误的意思是说,要在identity的列上显式的插入值,需要两个条件  
  1.明确的写出要插入的列名  
  2.set   identity_insert   table_name   on  
   
  显然,你违反了第一条  
   
   
  这样改写即可  
  set   identity_insert   identable   on  
  insert   into   identable(column1,column2,...)   select   column1,column2,...   from   #temp  
  set   identity_insert   identable   off  
posted @ 2006-04-12 09:52  RicoRui  阅读(372)  评论(0编辑  收藏  举报