SQL不是同一类型的变量赋值最好转换成统一类型,否则引起莫名错误
2012-05-11 17:29
253 查看
declare @EcountrydbID int,@Keyword varchar(200),@EproductId int ,@PicPath varchar(300),
@OldCountryDBID int,@OldCountryChoosedProductsIds varchar(1000);
set @OldCountryChoosedProductsIds='';
set @EproductId=0;
set @OldCountryDBID=0;
declare mycursor cursor for
--香港--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=90 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t1
union all
--印度--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=99 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t2
union all
--意大利--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=104 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t3
union all
--马来西亚--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=149 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t4
union all
--巴基斯坦--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=170 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t5
union all
--美国--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=223 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t6
union all
--沙特阿拉伯--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=184 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t7
union all
--新加坡--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=189 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t8
union all
--韩国--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=115 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t9
union all
--台湾--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=217 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t10
union all
--泰国--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=207 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t11
union all
--越南--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=231 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t12
union all
--澳大利亚--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=14 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t13
open mycursor
fetch next from mycursor into @EcountrydbID,@Keyword
while (@@fetch_status=0)
begin
if(@OldCountryDBID<>@EcountrydbID)
begin
set @OldCountryDBID=@EcountrydbID;
set @OldCountryChoosedProductsIds='';
end
else
begin
if(@OldCountryChoosedProductsIds='')
set @OldCountryChoosedProductsIds=Convert(varchar,@EproductId);
else
set @OldCountryChoosedProductsIds=@OldCountryChoosedProductsIds+','+Convert(varchar,@EproductId);
print @OldCountryChoosedProductsIds;
end
declare @oldKeyWord varchar(200)
set @oldKeyWord=@Keyword;
exec CD_DealWithKeyWord @Keyword output
--print @Keyword
select top 1 @EproductId=EproductId,@PicPath=PicPath from Eproduct_search where EcountryDBID=@EcountrydbID and contains(keyword,@Keyword)
and EproductId not in (select col from dbo.ecvv_split(@OldCountryChoosedProductsIds,','))
order by companylevel asc,ecvvpv desc,last_update_datetime asc
insert into EGlobalChannelHotSearch values(@EcountrydbID,@oldKeyWord,@EproductId,@PicPath,getdate());
print @EproductId;
fetch next from mycursor into @EcountrydbID,@Keyword
end
close mycursor
deallocate mycursor
@OldCountryDBID int,@OldCountryChoosedProductsIds varchar(1000);
set @OldCountryChoosedProductsIds='';
set @EproductId=0;
set @OldCountryDBID=0;
declare mycursor cursor for
--香港--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=90 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t1
union all
--印度--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=99 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t2
union all
--意大利--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=104 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t3
union all
--马来西亚--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=149 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t4
union all
--巴基斯坦--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=170 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t5
union all
--美国--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=223 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t6
union all
--沙特阿拉伯--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=184 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t7
union all
--新加坡--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=189 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t8
union all
--韩国--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=115 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t9
union all
--台湾--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=217 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t10
union all
--泰国--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=207 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t11
union all
--越南--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=231 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t12
union all
--澳大利亚--
select * from (select top 6 EcountrydbID,Keyword from EcountryRelatedKeyword
inner join Ehotsearchkeyword on EhotsearchkeywordID=Ehotsearchkeyword_ID
where EcountryDBID=14 order by EcountryRelatedKeyword.ProductCount desc,SortOrder) t13
open mycursor
fetch next from mycursor into @EcountrydbID,@Keyword
while (@@fetch_status=0)
begin
if(@OldCountryDBID<>@EcountrydbID)
begin
set @OldCountryDBID=@EcountrydbID;
set @OldCountryChoosedProductsIds='';
end
else
begin
if(@OldCountryChoosedProductsIds='')
set @OldCountryChoosedProductsIds=Convert(varchar,@EproductId);
else
set @OldCountryChoosedProductsIds=@OldCountryChoosedProductsIds+','+Convert(varchar,@EproductId);
print @OldCountryChoosedProductsIds;
end
declare @oldKeyWord varchar(200)
set @oldKeyWord=@Keyword;
exec CD_DealWithKeyWord @Keyword output
--print @Keyword
select top 1 @EproductId=EproductId,@PicPath=PicPath from Eproduct_search where EcountryDBID=@EcountrydbID and contains(keyword,@Keyword)
and EproductId not in (select col from dbo.ecvv_split(@OldCountryChoosedProductsIds,','))
order by companylevel asc,ecvvpv desc,last_update_datetime asc
insert into EGlobalChannelHotSearch values(@EcountrydbID,@oldKeyWord,@EproductId,@PicPath,getdate());
print @EproductId;
fetch next from mycursor into @EcountrydbID,@Keyword
end
close mycursor
deallocate mycursor
相关文章推荐
- 防止Sql注入字符串 , 变量赋值时防止为空和类型转换
- SQL 如何把@变量 转换为字符类型
- (SQL)将 expression 转换为数据类型 int 时发生算术溢出错误 2种快速处理方法
- SQL中查询ORCALCE库数据 报错误:从数据类型 DBTYPE_DBTIMESTAMP 转换为 datetime 时出错
- com.microsoft.sqlserver.jdbc.SQLServerException: 将 IDENTITY 转换为数据类型 numeric 时出现算术溢出错误。
- Ironpython及其他托管语言中值类型最好使用构造函数赋值,否则无法赋值的问题
- 关于结构体对其方式错误引起的变量赋值错误
- sql 将 varchar 值转换为数据类型为 int 的列时发生语法错误 的解决办法
- [PowerShell入门]变量、赋值、算术运算、类型转换、数组、注释
- SQL查询时常用,但不熟悉的相关语句-----邮标,行号,临时表,类型转换,字符串函数,sql 判断语句,检查是不是数字,变量,sql split 函数
- C语言学习2:sizeof ,数据类型,scanf,算式操作,赋值与比较操作,逻辑操作,位的操作,条件运算符,特异赋值结果,强制转换,使用变量要注意的
- 解决SQL将varchar值转换为数据类型为int的列时发生语法错误
- pl/sql中如何给boolean类型的变量赋值
- C++重载逗号,括号,类型转换,实现以奇怪的方式给变量赋值
- Python 变量(赋值,数据类型,数据类型转换)
- sql 聚合函数 sum 消息 8115,级别 16 将 expression 转换为数据类型 int 时出现算术溢出错误。
- 在做一些复杂的类型转换之前(比如将一个数据转换成一个属性的类型,属性可能为可空类型)先判断该类型是否为可空类型,否则会报如下错误:
- 6.PL_SQL――注释、数据类型的转换、变量的范围和限定词标签
- 变量_类型转换_ 算术运算符_转义字符_赋值和比较运算符_逻辑运算符_位运算符
- 原来sql里的变量要赋值再应用,否则为空