我有一个表正在尝试创建一个视图,以与需要特定列的新报表应用程序一起使用。我认为这应该很简单,但是列名使用的是错误的情况。具体来说,一栏是Customer_ID,而不是更改为用于创建视图的SQL语句中指定的customer_id。
原始表格为:Customer_ID | CustomerAddress | CustomerPhone
该视图必须为:customer_id | customer_address | customer_phone
视图为:Customer_ID | customer_address | customer_phone
创建视图的命令是:
BEGIN
SET NOCOUNT ON;
DECLARE @sql_customers nvarchar(max) = 'CREATE VIEW customers AS SELECT
oldcustomers.Customer_ID as customer_id,
oldcustomers.CustomerAddress as customer_address,
oldcustomers.CustomerPhone as customer_phone
FROM oldcustomers'
EXECUTE sp_executesql @sql_customers
END
答案 0 :(得分:0)
除非您使用区分大小写的排序规则,否则无需使用别名来更改大小写。
下面的方法应该可以避免不必要的麻烦...
CREATE VIEW customers
AS
SELECT
oc.customer_id,
oc.customeraddress,
oc.customerphone
FROM
dbo.oldcustomers oc;