Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a view, Help! 2

Status
Not open for further replies.

dday01

Technical User
Feb 1, 2002
138
0
0
US
Hi All,

I am a complete novice with SQL. I am trying to create a view based on an existing view (I think you are allowed to do this?). here is what my sql looks like:

SELECT *
FROM dbo.enc_serv_view
WHERE (ProgName = [HR (RW) HRRR ]) OR
(ProgName = [HR (RW) HRRR ]) OR
(ProgName = [HR (RW) Mental Hlth ]) OR
(ProgName = [HR (RW) Mental Health +])

When I try to run, I get an error that says "Invalid Column name "HR (RW) HRRR".

Any Ideas as to what I am doing wrong. My goal is to pull all records from the original view where the progname is equal to the values in my where statement.

Any help is appreciated.

D

 
WHERE part looks like something to put in a HP calculator... :X

What is HR (RW) HRRR ? If this is a string, use '' instead of []. Same for other values.
 
OK, first creating a view from a view is a recipe for inefficiency. It is much better to put all the code in one place. And for the most part stored procedures are more efficient (and far more flexible) than views.

Why your current query is not working is because you are trying to filter on character data but you have not enclosed the character part of the where clause in apostrophes. Try:
Code:
SELECT *
FROM dbo.enc_serv_view
WHERE (ProgName = 'HR (RW) HRRR ') OR
(ProgName = 'HR (RW) HRRR ') OR
(ProgName = 'HR (RW) Mental Hlth ') OR
(ProgName = 'HR (RW) Mental Health +')

Incidentally usually SELECT * is a poor practice as well. Only chose the fields you actually need for the purpose. Never ever return more data than you need. This is critical to performance in the long run. And a real pain to fix later when you have a production system running slowly and no one thing causing it and you have to try to figure out what fields you really needed when you didn't do it at the time it was fresh in your head.

Questions about posting. See faq183-874
Click here to learn Ways to help with Tsunami Relief
 
Thanks both of you for all of your help. I just needed a down and dirty solution for one report that I needed to put together.

D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top