SQLTeam.com | Weblogs | Forums

Create a VIEW that has a dynamic name with MS SQL?

tsql

#1

HI SQL team,

I am new to SQL query so trying to explain as much as I can to resolve my problem.

I have to create a view based on below scenario .

TABLE 1 : COLUMNS1,COLUMNS2,STUDENT ID, ATTENDANCE PER CLASS ( student id can be repeated multiple time per attendance )
TABLE 2 : COLUMNS1,COLUMNS2, STUDENT ID,TOTAL ATTENDANCE

Now I need to create individual student id view where their total attendance which is higher then 10 and have that view all colume from table 1

Thanks in advance

Maulik


#2

Not possible. You should instead create a view with student id as one of the column

CREATE VIEW your_view
AS
SELECT [STUDENT ID], [TOTAL ATTENDANCE]
FROM   [TABLE 2]
WHERE [TOTAL ATTENDANCE] >= 10

and add WHERE condition to filter the required [STUDENT ID]

SELECT *
FROM   your_view
WHERE [STUDENT ID] = 1234

#3

Actually, it IS possible with dynamic SQL but I can't think of a good reason why anyone would want to do such a thing for this problem.