declare @table table (col varchar(1)) insert into @table select 'a' union all select 'd' union all select 's' union all select 'h' union all select 'd'select MAX(col) from @table /* s */
declare @table table (col varchar(10)) insert into @table select 'abad' union all select 'ddddd' union all select 'jfefe' union all select 'hss' union all select 'dff'select MAX(col) from @table /* jfefe */直接用即可呀?
select MAX(col) from tb
#1. MAX可用在varchar列,值之间是字符串比较 #2. 如果varchar存储的是数字类型的数据,可转换后再比较,如max(cast(col as int))
--可以的 如果需要根据不同的排序规则排序(排序规则参见帮助文档)的话 可以自己指定 SELECT MAX(col collate Chinese_PRC_CI_AS ) FROM tb
CREATE TABLE #t1( khdm VARCHAR(20) )INSERT INTO #t1 SELECT 'a' INSERT INTO #t1 SELECT 'A'SELECT MAX(khdm collate Chinese_PRC_CI_AS ) FROM #t1 SELECT MAX(khdm collate Chinese_PRC_CS_AS ) FROM #t1
declare @table table (col varchar(1))
insert into @table
select 'a' union all
select 'd' union all
select 's' union all
select 'h' union all
select 'd'select MAX(col) from @table
/*
s
*/
declare @table table (col varchar(10))
insert into @table
select 'abad' union all
select 'ddddd' union all
select 'jfefe' union all
select 'hss' union all
select 'dff'select MAX(col) from @table
/*
jfefe
*/直接用即可呀?
select MAX(col) from tb
#2. 如果varchar存储的是数字类型的数据,可转换后再比较,如max(cast(col as int))
--可以的 如果需要根据不同的排序规则排序(排序规则参见帮助文档)的话 可以自己指定
SELECT MAX(col collate Chinese_PRC_CI_AS ) FROM tb
CREATE TABLE #t1(
khdm VARCHAR(20)
)INSERT INTO #t1 SELECT 'a'
INSERT INTO #t1 SELECT 'A'SELECT MAX(khdm collate Chinese_PRC_CI_AS ) FROM #t1
SELECT MAX(khdm collate Chinese_PRC_CS_AS ) FROM #t1