从创建视图中选择的问题 [英] Problem with Select from create view

查看:68
本文介绍了从创建视图中选择的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想通过联合选择"多个表中具有相同名称的列并从该视图中进行选择来创建视图.
我使用了本教程 [

Hi,

i''d like to create a view by "union selecting" a column with the same name in multiple tables and selecting from this view.
I used this tutorial [^] in different way''s but it still don''t work:

string selectCommandTemperature = "SELECT TOP " + countTempe + " [T/°C] FROM (CREATE VIEW temp AS (SELECT [T/°C] FROM Q3B UNION SELECT [T/°C] FROM Q3D))";


SqlCommand sqlCommandTemperature = new SqlCommand(selectCommandTemperature, sqlConnectionError);


SqlDataReader startPageTemperature = sqlCommandTemperature.ExecuteReader();



此构造导致SqlException:"CREATE"附近的语法错误

我是sql-noob,以前从未使用过sql,因此可能会对您有所帮助.



this construction cause an SqlException: wrong syntax near ''CREATE''

i''m a sql-noob and never worked with sql before so may you can help me.

推荐答案

在您的数据库中创建视图.在查询中调用视图
create the view in your database. in your query call the view


它不喜欢您试图创建视图,同时尝试从中读取视图的事实.我的也会返回
It doesn''t like the fact that you''re trying to Create a view, while trying to read from it at the same time. Mine also returns
''CREATE VIEW'' must be the first statement in a query batch

.

正如digimanus所建议的,首先创建视图,然后尝试从中查询数据.


.

As digimanus suggests, first create the view, then try to query data from it.


string selectCommandTemperature = "SELECT TOP " + countTempe + " [T/°C] FROM (SELECT [T/°C] FROM Q3B
UNION 
SELECT [T/°C] FROM Q3D) as t";


这篇关于从创建视图中选择的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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