Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 如何在sql server中自动连接三个字符串前两个字符_Sql Server_Stored Procedures - Fatal编程技术网

Sql server 如何在sql server中自动连接三个字符串前两个字符

Sql server 如何在sql server中自动连接三个字符串前两个字符,sql-server,stored-procedures,Sql Server,Stored Procedures,我想替换三列,比如第一列的前两个字符,第二列的第一个字符,第三列的第一个字符,以及当前年份的最后两位数字 我试过这样做 I have three columns in a table like name,village,state. Name='Samba Siva' Village='Kodur' State='Andra pradesh' 但它不起作用。i、 e:我想要像这样的输出 代码='SAKOA14'。 这里14是本年度的最后两位数字。 请告诉我如何编写查询请帮助我……你在找这样的东

我想替换三列,比如第一列的前两个字符,第二列的第一个字符,第三列的第一个字符,以及当前年份的最后两位数字

我试过这样做

I have three columns in a table like name,village,state.
Name='Samba Siva'
Village='Kodur'
State='Andra pradesh'
但它不起作用。i、 e:我想要像这样的输出 代码='SAKOA14'。 这里14是本年度的最后两位数字。
请告诉我如何编写查询请帮助我……

你在找这样的东西吗

select right(replace(name,2)+Cast(cast(coalesce(max(village),0) as varchar) as varchar),2) customercode
from(select top 1 customercode from K_FS_DistributorDetails order by customercode)r;
输出:

SELECT TOP 1 UPPER(LEFT(Name, 2) + LEFT(Village, 2) + LEFT(State, 1) + CONVERT(VARCHAR, YEAR(GETDATE()) % 100)) code
  FROM K_FS_DistributorDetails
 ORDER BY customercode DESC
|代码| |---------| |SAKOA14| 这里是演示

| CODE | |---------| | SAKOA14 |