Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Add new blank column with null/blank value

Author  Topic 

maya_zakry
Constraint Violating Yak Guru

379 Posts

Posted - 2010-12-08 : 02:15:12
Hi,
I have weird requirement to add a column without specifying the column name in view.

select usr, '', from tbluser OR
select usr, '' AS ' ' from tblusr

it's fine with normal query, but when i put in view, it cannot work with error : Create View or Function failed because no column name was specified for column 6.




~~~who controls the past controls the future, who controls the present controls the past. ¯\(º_o)/¯ ~~~

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-12-08 : 03:37:16
I don't know whats the purpose but you can create a view this way.

Create view TestView as
select name,id,null as [ ] from sysobjects
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-12-08 : 04:12:55
You should not have that garbage in your view!
Create an empty column where you need it in your application but not in your view.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-12-08 : 04:20:47
"You should not have that garbage in your view!"

But you don't know what the application is ...

Maybe the "application" is a user selecting from a VIEW directly into Excel ... in which case the Column Headings in the spreadsheet will start out as they come from the view - and it may be desirable that the users don't have to go in and fix them up every time they make a new spreadsheet query.
Go to Top of Page

maya_zakry
Constraint Violating Yak Guru

379 Posts

Posted - 2010-12-10 : 03:04:07
thx pk_bohra. but actually i need multiple blank column, so since we name the 1st one as [ ], the next blank column result in column unique error.

yes, kristen are right, it's for excel purpose afetr user import.

~~~who controls the past controls the future, who controls the present controls the past. ¯\(º_o)/¯ ~~~
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-12-10 : 03:47:11
Well - you could use multiple spaces, but I don't know whether that you be acceptable or not?

Actually ... turns out you can't, I just tried it, multiple spaces are treated as two spaces by the looks of it.

Can you have column names [*], [#], [.] etc. as being "fairly bland"?
Go to Top of Page
   

- Advertisement -