English 中文(简体)
页: 1
原标题:SQL alias gives invalid column name

Using the following SQL expression but I m getting an error.

select
  CampaignCustomer.CampaignCustomerID,
  convert(varchar, CampaignCustomer.ModifiedDate, 111) as startdate,
  CampaignCustomer.CampaignID,
  CampaignCustomer.CampaignCallStatusID,
  CampaignCustomer.UserID,
  CampaignCustomerSale.Value,
  Users.Name
from CampaignCustomer
  inner join CampaignCustomerSale
    on CampaignCustomer.CampaignCustomerID = CampaignCustomerSale.CampaignCustomerID
  inner join Users
    on CampaignCustomer.UserID = Users.UserID
where
  CampaignCustomer.CampaignCallStatusID = 21
  and CampaignCustomer.startdate =  2011/11/22       <------- THIS
order by
  startdate desc,
  Users.Name asc

错误:

Msg 207, Level 16, State 1, Line 1
Invalid column name startdate .

我可以肯定一下WHERE条款中的“startdate,但可在我的上查阅。 页: 1 什么错误?

Edit:
And no, it is not possible for me to change the datatype to date instead of datetime. The time is needed elsewhere. But in this case, I need only to get all posts on a specific date and I really don t care about what time of the date the modifieddate is :)

或许还需要另一种方法而不是转换?

最佳回答

页: 1 WHERE Clause.


修改如下:

where
  CampaignCustomer.CampaignCallStatusID = 21
  and convert(varchar, CampaignCustomer.ModifiedDate, 111) =  2011/11/22  
问题回答

这是:

select 
  CampaignCustomer.CampaignCustomerID, 
  convert(varchar, CampaignCustomer.ModifiedDate, 111) as startdate, 
  CampaignCustomer.CampaignID, 
  CampaignCustomer.CampaignCallStatusID, 
  CampaignCustomer.UserID, 
  CampaignCustomerSale.Value, 
  Users.Name 
from CampaignCustomer 
  inner join CampaignCustomerSale 
    on CampaignCustomer.CampaignCustomerID = CampaignCustomerSale.CampaignCustomerID 
  inner join Users 
    on CampaignCustomer.UserID = Users.UserID 
where 
  CampaignCustomer.CampaignCallStatusID = 21 
  and convert(varchar, CampaignCustomer.ModifiedDate, 111) =  2011/11/22 
order by 
  startdate desc, 
  Users.Name asc 

页: 1 该条款没有具体内容,在以上询问中,我用它所代表的内容取代你的内容。

您只字不提一下一下一下一下Kall的哪些内容? 服务器:

where
  CampaignCustomer.CampaignCallStatusID = 21
  and CAST(CampaignCustomer.ModifiedDate AS DATE) =  20111122 

您可将其带至<代码>D-仅为这一比较。

另外,我建议<>途径使用ISO-8601标准格式,如果你需要比较一个显示日期——ISO-8601确定一个日期为。 YYYYMMDD,是SQ的唯一格式 永远发挥作用的服务器——无论你有何种语言/区域环境。 某一日期的任何其他说明,总是在你的服务器中受到环境的影响——它可能为你工作,但我对其他人说,它会打破。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签