I want to display output like this with SQL Server [closed]

7gcisfzg  于 2023-11-16  发布在  SQL Server
关注(0)|答案(1)|浏览(154)

Closed. This question needs details or clarity . It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post .

Closed 2 months ago.
Improve this question

this is my original table in database.

nameqty
QMORIASDWAD 1
QMORIASDWAD 3
QMORIASDWAD 4
QMORIASDWAD 5
QMORIASDWAD 6
QMORIASDWAD 7
QMORIASDWAD 8

and I want my result output with select to be like this.

nameqty
qm21
qm23
qm24
qm25
qm26
qm27
qm28
4uqofj5v

4uqofj5v1#

your data

CREATE TABLE yourtable(
   name VARCHAR(100) NOT NULL 
  ,qty  INTEGER  NOT NULL
);
INSERT INTO yourtable(name,qty) VALUES 
('QMORIASDWAD',1),
('QMORIASDWAD',3),
('QMORIASDWAD',4),
('QMORIASDWAD',5),
('QMORIASDWAD',6),
('QMORIASDWAD',7),
('QMORIASDWAD',8);

Just use Concat , Lower and Left function

SELECT 
CONCAT(LOWER(left(name,2)),2) name,
qty 
FROM YourTable

dbfiddle

Based on your query,you can use with

with t as (
  SELECT 
    DISTINCT name, 
    qty 
  FROM 
    db 
  WHERE 
    cast (prod_date AS DATE) = cast (
      getdate () AS DATE
    ) 
    and name <> 'asd'
) 

SELECT 
CONCAT (LOWER(left(NAME, 2)),2) NAME
,qty
FROM t

相关问题