如何在MS SQL中生成SKU ID

时间:2017-11-02 11:00:51

标签: sql-server

有谁能告诉我,我们怎样才能生成像Ram-Me-123,Laptop-dell-1234578这样的SKU。此格式应与产品名称和公司或某些规格和序列号

相似

1 个答案:

答案 0 :(得分:1)

您没有提供样本数据或其他任何可以帮助我们的帮助,但这是一个简单的例子:

CREATE TABLE Products (
    SerialNumber VARCHAR(20),
    Name VARCHAR(20),
    CompanyName VARCHAR(20)
    );
INSERT INTO Products VALUES
('1234578', 'Laptop', 'Dell'),
('9512369', 'Laptop', 'Lenovo'),
('8547-H2', 'Phone', 'Sonny'),
('8787963', 'Phone', 'Condor');

SELECT *, Name+ '-' +CompanyName+ '-' +SerialNumber AS SKU
FROM Products;

结果:

+--------------+--------+-------------+-----------------------+
| SerialNumber |  Name  | CompanyName |          SKU          |
+--------------+--------+-------------+-----------------------+
| 1234578      | Laptop | Dell        | Laptop-Dell-1234578   |
| 9512369      | Laptop | Lenovo      | Laptop-Lenovo-9512369 |
| 8547-H2      | Phone  | Sonny       | Phone-Sonny-8547-H2   |
| 8787963      | Phone  | Condor      | Phone-Condor-8787963  |
+--------------+--------+-------------+-----------------------+