简体   繁体   中英

SQL Server 2008 / 2012 - views & sql formatting

Hopefully this is a newbie question.

So if I have kind of a long set of selects in my SQL and a couple of sub-selects within my where clause, I'm less than satisfied with the formatting in the view designer, which appears to be the only way to display/show my views after they are saved.

So, in short, is there any way to directly edit my views within SSMS, and have the views retain the formatting in my code?

ie;

select case /*comment */
  when a = 5  
   then b = 2 
   else b = 4  /* why b 4 */
  end as field_1,
  dt as field_2,...

get's all mashed up

select case /*comment */     when a = 5                  
then b = 2                 else b = 4  /* why b 4 */              
end as field_1,             
dt as field_2,...

Or something along those lines.

Are you using the query designer? Instead, use an SSMS query window. From the SSMS Object Explorer, right-click on the view and select Script View as-->Alter To-->New Query Editor window. Format the view source in the query window and run the script to change the view. Your formatting will be preserved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM