从我的代码我想检查哪个更好 [英] From My Code I Want To Check Which Is Greater

查看:55
本文介绍了从我的代码我想检查哪个更好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个 Query1 明智获取数据所有

选择cmn_minor_code,将(char,cbm_batch_start_dt,106)转换为Course_start_date,将cbm_batch_id转换为Batch_ID,

bthidd =(从BATCHID中选择前1个EID,其中BID = CBM.cbm_batch_id和B_ACTIV<>'D')

来自CO_BATCH_MASTER CBM WHERE

CBM.cbm_batch_id不在(选择Blocked_Batch_id来自

Tb_SMS_Blocked_Batches,其中Active<>'D')和cbm_active<> 'D'

和CBM.cmn_minor_code不在('RMFA','RSSO','RMC','RMFA_C','RSSO_C','RMC_C')

和cbm_batch_start_dt之间'20 -Feb-2014'

和'20 -Feb-2014'订单来自cbm_batch_start_dt



Cusrsor使用获取数据同一天

ID日期

ARBA / B146 2014年2月20日

ARPA / B147 2014年2月20日
$ b在Query1数据获得TOP 1值得到以下查询后,$ b





QUERY2

声明@EID varchar(50)

从BATCHID BI,CO_BATCH_MASTER CBM中选择前1 @EID = ltrim(rtrim(ltrim(isnull(BI.EID,'')))) .BID = CBM.cbm_batch_id和bi.B_ACTIV<>'D'和CBM.cbm_active<>'D'

和cbm.cbm_batch_start_dt = @cbm_batch_start_dt和CBM.cmn_minor_code=@cmn_minor_code ORDER BY cbm_batch_start_dt DESC



以上Quer Wise在分割代码之后得到两个值使用





SET @ strAlphaNumeric = @ EID

声明@strAlphaNumeric varchar(50)

DECLARE @intAlpha INT

SET @intAlpha = PATINDEX('%[0-9]%',@ ssAlphaNumeric)

select Cast(SUBSTRING(@strAlphaNumeric) ,@ intAlpha,len(@strAlphaNumeric))as int)

选择SUBSTRING(@ strAlphaNumeric,1,@ intAlpha-1)





运行上面的代码显示输出如下



147

146



ARPA / B

ARPA / B







我想检查147或146哪个更大。



从上面的147更大。



获取输出147.



来自我上面的代码我需要做什么改变才能得到147输出。

This Query1 Wise Get Data in all
select cmn_minor_code , convert(char,cbm_batch_start_dt,106) as Course_start_date,cbm_batch_id as Batch_ID,
bthidd = (select top 1 EID from BATCHID where BID = CBM.cbm_batch_id and B_ACTIV<>'D')
from CO_BATCH_MASTER CBM WHERE
CBM.cbm_batch_id not in(select Blocked_Batch_id from
Tb_SMS_Blocked_Batches where Active<>'D') and cbm_active <> 'D'
and CBM.cmn_minor_code not in('RMFA','RSSO','RMC','RMFA_C','RSSO_C','RMC_C')
and cbm_batch_start_dt between '20-Feb-2014'
and '20-Feb-2014' order by cbm_batch_start_dt

Cusrsor Using Get Data with same date
ID Date
ARBA/B146 20-Feb-2014
ARPA/B147 20-Feb-2014

after Query1 data get TOP 1 value get below query wise

QUERY2
Declare @EID varchar(50)
select top 1 @EID = ltrim(rtrim(ltrim(isnull(BI.EID,'')))) from BATCHID BI,CO_BATCH_MASTER CBM where bi.BID = CBM.cbm_batch_id and bi.B_ACTIV<>'D' and CBM.cbm_active<>'D'
and cbm.cbm_batch_start_dt = @cbm_batch_start_dt and CBM.cmn_minor_code=@cmn_minor_code ORDER BY cbm_batch_start_dt DESC

Above Quer Wise Get Two values after split below code using


SET @strAlphaNumeric=@EID
Declare @strAlphaNumeric varchar (50)
DECLARE @intAlpha INT
SET @intAlpha = PATINDEX('%[0-9]%', @strAlphaNumeric)
select Cast(SUBSTRING(@strAlphaNumeric,@intAlpha, len(@strAlphaNumeric)) as int)
select SUBSTRING(@strAlphaNumeric,1,@intAlpha-1)


Running the above code shows output as follows

147
146

ARPA/B
ARPA/B



I want to check 147 or 146 which is greater.

From the above 147 is greater.

for getting a output 147.

from my above code what changes i have to made to get 147 output.

推荐答案

如果你想获得最高,那么你可以这样做:

If you want to get the highest, then you could do something like this:
--set variables
declare @Highest int;set @Highest = 0;
declare @Temp int;

--populate @Temp - check which is higher @Temp or @Highest
select @Temp=Cast(SUBSTRING(@strAlphaNumeric,@intAlpha,len(@strAlphaNumeric)) as int);
if @Temp > @Highest begin set @Highest = @Temp end;

select @Temp=Cast(SUBSTRING(@strAlphaNumeric1,@intAlpha,len(@strAlphaNumeric1)) as int);
if @Temp > @Highest begin set @Highest = @Temp end;

--final result
select @Highest HighestNumber;



或者类似的东西:


Or alternatively something like:

--set variables
declare @Num01 int;
declare @Num02 int;

--populate
select @Num01=Cast(SUBSTRING(@strAlphaNumeric,@intAlpha,len(@strAlphaNumeric)) as int);
select @Num02=Cast(SUBSTRING(@strAlphaNumeric1,@intAlpha,len(@strAlphaNumeric1)) as int);

--compare
if @Num01 > @Num02 begin
	select @Num01 Highest;
end;
else if @Num02 > @Num01 begin
	select @Num02 Highest;
end;

--or get max
select max(num) Highest from 
(
	select @Num01 num
	union
	select @Num02 num
) numbers;


这篇关于从我的代码我想检查哪个更好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆