Sql语句根据用户首选项选择列 [英] Sql Statement to select the columns acoording to user preference

查看:82
本文介绍了Sql语句根据用户首选项选择列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI朋友,

我遇到了问题...我有一个表EMployeeId,在此我创建了3个列(EmpName,EmpId,EmpADD)我已经插入了10个行,其中EmpId从1到10.现在我的问题是我想在序列5,8,2,3,4,6,7中选择表EmployeeId ,9,10 ......

提前谢谢。

HI friends,
I stuck on a problem...I have a table EMployeeId and within this I had created 3 rows columns (EmpName, EmpId, EmpADD) and i had inserted 10 columns rows into it having EmpId from 1 to 10. Now my question is i want to select the table EmployeeId in the sequence 5,8,2,3,4,6,7,9,10...
Thank you in advance.

推荐答案

一种方法是将订单的用户偏好设置为以某种方式表...让我们说你有一个表
One way is to get the user preference for the order into a table somehow ... let's say you have a table
CREATE TABLE UserOrder
(
OrderId INT IDENTITY(1,1),
EmpId INT
);



EmpId将成为EmployeeId表的外键。



如何获得这些价值在那里取决于你。假设您将逗号分隔列表传递给存储过程,然后查看此主题 [ ^ ]获取进入UserOrder表的方法。



这是一个例子:




The EmpId is going to be a foreign key to your EmployeeId table.

How you get those values in there is up to you. Say you pass a comma separated list to a Stored Procedure then see this thread[^] for a way of getting it into the UserOrder table.

Here is an example:

DECLARE @TheOrder VARCHAR (150)

SET @TheOrder = '5,8,2,3,4,6,7,9'

DECLARE @EmpId VARCHAR

INSERT INTO UserOrder (EmpId)
    SELECT items
    FROM [dbo].[Split] (@TheOrder, ',')

SELECT E.*
FROM EmployeeId E
INNER JOIN UserOrder O ON E.EmpId = O.EmpId
ORDER BY O.OrderId





(NB请注意从函数返回的varchar项和存储在表中的int的隐式转换。)



(N.B. Note the implicit cast from the varchar items returned from the function and the int that is stored on the table.)


这篇关于Sql语句根据用户首选项选择列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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