找到错误的解决方案...! [英] Find the Solution of the Error...!
本文介绍了找到错误的解决方案...!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
select t2.tableName as 'Table Name',t2.gametype as 'Limit',Convert(varchar,Convert(numeric(18,2),t2.smallblind))
+ '/' + Convert(varchar,Convert(numeric(18,2),t2.bigblind)) as 'Stakes',t3.GameName as 'Game Name'
from tblgameinfo t1 join tblGameTables t2 on (t1.tableid=t2.tableid) join tblGames t3 on (t3.gameid = t1.gameid)
where (t2.skinid= 6 or t2.skinid= 0) and t1.nickname = 'Player1' --order by nickname
union all
Select t2.tablename as'Table Name',t1.TableID as 'Limit',t1.TournamentID as 'Stakes',t3.TournamentName'Game Name'
from tblRegistration t1 join tblGameTables_TRMNT t2 on t1.TableID=t2.TableID join tblTournaments t3 on t3.tournamentID=t1.TournamentID
where t3.skinid= 6 and t1.nickname='Player1' AND t1.Eliminated='N' and t1.TableID >-1 and t3.State='P' and t3.TournamentType='S'
如果我一次执行每个查询的话..!但是当我尝试执行
union All关键字会生成这样的错误..!
if i execute the each queary at a time its work..! but when i tried to execute with
union All keyword its generate a error like this..!
"Error converting data type varchar to numeric."
请告诉我如何管理查询!
please tell me how i have to manage queary!
推荐答案
我将使用CAST代替CONVERT
I would use CAST in stead of CONVERT
select t2.tableName as 'Table Name',
t2.gametype as 'Limit',
Cast(t2.smallblind as varchar) + '/' + Cast(t2.bigblind as varchar) as 'Stakes',
t3.GameName as 'Game Name'
from tblgameinfo t1
join tblGameTables t2 on (t1.tableid=t2.tableid)
join tblGames t3 on (t3.gameid = t1.gameid)
where (t2.skinid= 6 or t2.skinid= 0)
and t1.nickname = 'Player1'
--order by nickname
union all
Select t2.tablename as 'Table Name',
t1.TableID as 'Limit',
cast(t1.TournamentID as varchar) as 'Stakes',
t3.TournamentName'Game Name'
from tblRegistration t1
join tblGameTables_TRMNT t2 on t1.TableID=t2.TableID
join tblTournaments t3 on t3.tournamentID=t1.TournamentID
where t3.skinid= 6
and t1.nickname='Player1'
AND t1.Eliminated='N'
and t1.TableID >-1
and t3.State='P'
and t3.TournamentType='S'
使用UNION
或UNION ALL
子句时,需要确保两个查询中返回的列的类型相同.如果顺序不同,则会出现此错误.
例如第一个查询Convert(varchar,Convert(numeric(18,2),t2.smallblind))
中的第三列是varchar
.
但是,第二个查询中的第三列似乎是numeric
t1.TournamentID as ''Stakes''
-因此您会收到此错误.
When you use theUNION
orUNION ALL
clause, you need to ensure that the types of the columns being returned in both the queries is the same. If the order is different, you will get this error.
For e.g. the third column in the first queryConvert(varchar,Convert(numeric(18,2),t2.smallblind))
isvarchar
.
However, the third column in the second query appears to benumeric
t1.TournamentID as ''Stakes''
- hence you get this error.
根据我的观点,您只需检查您的select语句即可.
在第一个选择语句中,第三个参数是varchar,即您选择的内容(Convert(varchar,Convert(numeric(18,2),t2.smallblind))
+''/''+ Convert(varchar,Convert(numeric(18,2),t2.bigblind))作为``Stakes''),在第二个select语句中,第三个参数可能是数字或整数,即(t1. TournamentID为"Stakes"),因此在并集之前,请在select语句中同时添加一个varchar.
如果它困扰了您的查询,请标记
otharwise使我恢复原状
as per my opinion,you just check your select statement.
in first select statement,third argument is varchar ie what u selecting (Convert(varchar,Convert(numeric(18,2),t2.smallblind))
+ ''/'' + Convert(varchar,Convert(numeric(18,2),t2.bigblind)) as ''Stakes'') and in second select statement third argument is might be it numeric or int ie (t1.TournamentID as ''Stakes'') so before union all make that one also varchar in select statement.
mark if Its anwered your query plz
otharwise revert me back
这篇关于找到错误的解决方案...!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文