SQL view error "more column names specified than columns defined"

If you ever get a ColdFusion error message such as the following:

Error Executing Database Query. [Macromedia][SQLServer JDBC Driver][SQLServer]View or function 'dbo.myviewname' has more column names specified than columns defined.

You/somebody probably just added or deleted a column from the view definition. Then, if you have a cfquery that does a "select *" against the view, that error will result.

The fix is to run the following system stored procedure in SQL Query Analyzer, to refresh the view: sp_refreshview 'myviewname'

Doing a Subquery in SQL

For my own future reference... This will lookup a value (emailaddress) from table2, to use in where clause in table1.

select *
from table1
where EmailAddress = (select EmailAddress from table2 where UserID = '#URL.UID#')

BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner