Views, UDFs

Aug 15, 2006

I know there is a lot of information already out there on this topic,
but given the following scenario...

--------------------------------------------------------------------------------------------------------------------------------------
Create a view like so ( pardon the pseudo-code )...

CREATE View vwContactAddresses
Select * FROM Contact INNER JOIN Address ON Contact.ContactID =
Address.ContactID

And then do a sargable select from the view using a stored procedure

CREATE STORED PROCEDURE spSelect_ContactAddresses
@ContactID int
AS
Select * FROM vwContactAddresses WHERE ContactID = @ContactID
--------------------------------------------------------------------------------------------------------------------------------------

In my understanding, "vwContactAddresses" would be substituted with the
actual SQL join statement when the view is accessed.

So for the stored procedure in question an execution plan for
"Select * FROM Contact INNER JOIN Address ON Contact.ContactID =
Address.ContactID WHERE ContactID = @ContactID" would be cached.
Correct?

With regards to execution plan caching, is this not the same as
creating an inline UDF that takes parameters or just creating a stored
procedure that would do the join w/out the view reference?

View 3 Replies


ADVERTISEMENT

Business Rules -&&> Using Lots Of UDFs && Views

Sep 7, 2007

I am in the process of building my first "large scale" database system (after 15+ years of developing Windows Apps and Web Apps) - so I am very VERY "Green" when it comes to Database development & SQL et al.

A little context setting: I am building a multi-tier Statistical Analysis & Reporting system where the "end product" will be Reports created in Reporting Services. There are a ton of business rules that I am implementing in a Business Logic Tier (hidden from the "end user" by a Data Access Tier) comprised of SQL in the form of UDFs (scalar) and Views.

The question: I have been reading that UDFs cause a performance hit compared to things like in-line functions. Alot of the Rules (implemented as Scalar UDFs) build on each other so that the output of UDF #1 is used as input to UDF #2.

So far I am implementing the Business Logic as a hierarchy of Views (7 Views to be exact) with each view implementing multiple Rules; each Rule basically a Scalar UDF. Below is an example of what I am doing:

Example

View #1 -> Select A, B, C, funcX1(A) as ValueX1, funcY1(B, C) as ValueY1 FROM someView

Then
View #2 -> Select A, B, C, ValueX1, ValueY1, funcX2 (ValueX1) as ValueX2, funcY2(ValueY2) as ValueY2 FROM View#1

Currently I have a hierarchy of 7 views that each use UDFs to implement the Business Rules, where the value calculated from a UDF in one View is used as input to UDF in a View further down the Hierarchy.

Is there a better way of implementing all of the Rules instead of using multiple Views with a bunch of UDFs?

The "end product" dataset is then exposed as a Stored Procedure to the reports in Reporting Services.

Any help would be GREATLY appreciated.

Thanks!
- marty

View 5 Replies View Related

Tracing UDFs

Jun 6, 2006

How would I go about tracing UDF performance in profiler? I'd like to
specifically know the impact of the UDF without having to dig into the
execution plan of the statement containing it. Is this possible?

View 1 Replies View Related

Replicate SPs And UDFs

Aug 2, 2007

Can changes made to replicated stored procedures (and User-defined Functions) on the Publisher update the Subscriber database?

If I ALTER a SP (or UDF) on Database1 with peer-to-peer Transaction Replication to Database2, will the alter replicate to the Subscriber(s)?

Thomas


ThomBeaux

View 10 Replies View Related

Computed Columns Or UDFs

Jul 8, 2004

Hi,

What is the difference between a computed column and a UDF?
Is a computed column the same as the "Formula" field under Design Table in Enterprise Manager?
Also, what is the proper syntax for the Formula field? Can I use regular SQL on it or is there more to it?

thanks,
Frank

View 1 Replies View Related

UDFs GETWORDCOUNT, GETWORDNUM

Jun 17, 2005

-- Author: Igor Nikiforov, Montreal, EMail: udfs@sympatico.ca
-- GETWORDCOUNT() User-Defined Function Counts the words in a string.
-- GETWORDCOUNT(@cString[, @cDelimiters])
-- Parameters
-- @cString nvarchar(4000) - Specifies the string whose words will be counted.
-- @cDelimiters nvarchar(256) - Optional. Specifies one or more optional characters used to separate words in @cString.
-- The default delimiters are space, tab, carriage return, and line feed. Note that GETWORDCOUNT( ) uses each of the characters in @cDelimiters as individual delimiters, not the entire string as a single delimiter.
-- Return Value smallint
-- Remarks GETWORDCOUNT() by default assumes that words are delimited by spaces or tabs. If you specify another character as delimiter, this function ignores spaces and tabs and uses only the specified character.
-- If you use 'AAA aaa, BBB bbb, CCC ccc.' as the target string for dbo.GETWORDCOUNT(), you can get all the following results.
-- declare @cString nvarchar(4000)
-- set @cString = 'AAA aaa, BBB bbb, CCC ccc.'
-- select dbo.GETWORDCOUNT(@cString, default) -- 6 - character groups, delimited by ' '
-- select dbo.GETWORDCOUNT(@cString, ',') -- 3 - character groups, delimited by ','
-- select dbo.GETWORDCOUNT(@cString, '.') -- 1 - character group, delimited by '.'
-- See Also GETWORDNUM() User-Defined Function
-- UDF the name and functionality of which correspond to the same built-in function of Visual FoxPro
CREATE function GETWORDCOUNT (@cSrting nvarchar(4000), @cDelimiters nvarchar(256) )
returns smallint
as
begin
-- if no break string is specified, the function uses spaces, tabs and line feed to delimit words.
set @cDelimiters = isnull(@cDelimiters, space(1)+char(9)+char(10))
declare @p smallint, @end_of_string smallint, @wordcount smallint
select @p = 1, @wordcount = 0
select @end_of_string = 1 + datalength(@cSrting)/(case SQL_VARIANT_PROPERTY(@cSrting,'BaseType') when 'nvarchar' then 2 else 1 end) -- for unicode

while dbo.CHARINDEX_BIN(substring(@cSrting, @p, 1), @cDelimiters, 1) > 0 and @end_of_string > @p -- skip opening break characters, if any
set @p = @p + 1

if @p < @end_of_string
begin
set @wordcount = 1 -- count the one we are in now count transitions from 'not in word' to 'in word'
-- if the current character is a break char, but the next one is not, we have entered a new word
while @p < @end_of_string
begin
if @p +1 < @end_of_string and dbo.CHARINDEX_BIN(substring(@cSrting, @p, 1), @cDelimiters, 1) > 0 and dbo.CHARINDEX_BIN(substring(@cSrting, @p+1, 1), @cDelimiters, 1) = 0
select @wordcount = @wordcount + 1, @p = @p + 1 -- Skip over the first character in the word. We know it cannot be a break character.
set @p = @p + 1
end
end

return @wordcount
end
GO

-- Author: Igor Nikiforov, Montreal, EMail: udfs@sympatico.ca
-- GETWORDNUM() User-Defined Function
-- Returns a specified word from a string.
-- GETWORDNUM(@cString, @nIndex[, @cDelimiters])
-- Parameters @cString nvarchar(4000) - Specifies the string to be evaluated
-- @nIndex smallint - Specifies the index position of the word to be returned. For example, if @nIndex is 3, GETWORDNUM( ) returns the third word (if @cString contains three or more words).
-- @cDelimiters nvarchar(256) - Optional. Specifies one or more optional characters used to separate words in @cString.
-- The default delimiters are space, tab, carriage return, and line feed. Note that GetWordNum( ) uses each of the characters in @cDelimiters as individual delimiters, not the entire string as a single delimiter.
-- Return Value nvarchar(4000)
-- Remarks Returns the word at the position specified by @nIndex in the target string, @cString. If @cString contains fewer than @nIndex words, GETWORDNUM( ) returns an empty string.
-- See Also
-- GETWORDCOUNT() User-Defined Function
-- UDF the name and functionality of which correspond to the same built-in function of Visual FoxPro
CREATE function GETWORDNUM (@cSrting nvarchar(4000), @nIndex smallint, @cDelimiters nvarchar(256) )
returns nvarchar(4000)
as
begin
-- if no break string is specified, the function uses spaces, tabs and line feed to delimit words.
set @cDelimiters = isnull(@cDelimiters, space(1)+char(9)+char(10))
declare @i smallint, @j smallint, @p smallint, @q smallint, @qmin smallint, @end_of_string smallint, @LenDelimiters smallint, @outstr nvarchar(4000)
select @i = 1, @p = 1, @q = 0, @outstr = ''
select @end_of_string = 1 + datalength(@cSrting)/(case SQL_VARIANT_PROPERTY(@cSrting,'BaseType') when 'nvarchar' then 2 else 1 end) -- for unicode
select @LenDelimiters = datalength(@cDelimiters)/(case SQL_VARIANT_PROPERTY(@cDelimiters,'BaseType') when 'nvarchar' then 2 else 1 end) -- for unicode

while @i <= @nIndex
begin
while dbo.CHARINDEX_BIN(substring(@cSrting, @p, 1), @cDelimiters, 1) > 0 and @end_of_string > @p -- skip opening break characters, if any
set @p = @p + 1

if @p >= @end_of_string
break

select @j = 1, @qmin = @end_of_string -- find next break character it marks the end of this word
while @j <= @LenDelimiters
begin
set @q = dbo.CHARINDEX_BIN(substring(@cDelimiters, @j, 1), @cSrting, @p)
set @j = @j + 1
if @q > 0 and @qmin > @q
set @qmin = @q
end

if @i = @nIndex -- this is the actual word we are looking for
begin
set @outstr = substring(@cSrting, @p, @qmin-@p)
break
end
set @p = @qmin + 1

if (@p >= @end_of_string)
break
set @i = @i + 1
end

return @outstr
end
GO


-- Is similar to the built-in function Transact-SQL charindex, but regardless of collation settings,
-- executes case-sensitive search
-- Author: Igor Nikiforov, Montreal, EMail: udfs@sympatico.ca
CREATE function CHARINDEX_BIN(@expression1 nvarchar(4000), @expression2 nvarchar(4000), @start_location smallint = 1)
returns nvarchar(4000)
as
begin
return charindex( cast(@expression1 as nvarchar(4000)) COLLATE Latin1_General_BIN, cast(@expression2 as nvarchar(4000)) COLLATE Latin1_General_BIN, @start_location )
end
GO

View 20 Replies View Related

How To Recompile / Refresh UDFs ?

Mar 6, 2007

Hi!I need to refresh an entire database.I can recompile SPs with sp_recompile (or DBCC FLUSHPROCINDB), andrefresh views with sp_refreshView, but I cannot find any way torefresh my user-defined functions (some of them are like views, withparameters).Any help appreciated :) !Ben

View 5 Replies View Related

Strange Behaviour Of System UDFs

Jan 28, 2004

Hi,

I have written an udf that checks for validations of an email address and returns 0 / 1 as per the validations. I came across an artical on MSDN that describes the steps to make my own system udf. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsqlpro01/html/sql01l1.asp

with help of that artical, I made my udf as a system udf. and now I can use it as follows.

select * , fn_isvalidemail(email) from #tp

now, I wanted to use this as a declarative check constraints in my tables. so I tried

create table testtable
( email_addr varchar (255) null CONSTRAINT CK_email_chk CHECK ( fn_isvalidemail(email) = 1) )

although this is syntax is logically correct, it does not get compiled

it gives me an error saying,

Server: Msg 195, Level 15, State 10, Line 2
'fn_isvalidemail' is not a recognized function name.


the strange part is that i made the function as another normal udf, It works in declarative constraints.

create table testtable
( email varchar (255) null CONSTRAINT CK_1p12 CHECK ( dbo.isvalidemail(email) = 1) )


Any thoughts on this ?

- Amit

View 2 Replies View Related

UDFs Are Pre-compiled Or Not Like Stored Procedures?

Jun 9, 2015

I have always learn that UDFs are not Pre-Compiled while Stored procedures are. But I always had this questions why are UDFs are not Pre-Compiled.

I searched online for the answer but dint get an concrete justification on the same.

View 3 Replies View Related

Calling UDFs On Linked Server

Feb 25, 2008

Hello,

How can I call UDFs on linked servers in SQL Server 2005?

More details:

I have some UDFs on Instance "VAXPServerA" in Database "DB1", for example "getSomething(number)".

It might look like this (for example):

----
CREATE FUNCTION [dbo].[getSomething] (
@theNumber int
)
RETURNS int AS
BEGIN
DECLARE @result int
SET @result = theNumber * 5
RETURN @result
END
----

I can call this function inside of the DB by typing:

----
SELECT dbo.getSomething(5)
----

I also can call the function from another DB on instance "VAXPServerA" by typing:

----
SELECT DB1.dbo.getSomething(5)
----

I have a second instance called "VAXPServerB", and "VAXPServerA" is a linked server in "VAXPServerB". I can do selects and stuff, it works fine.
But when I want to call the function...

----
SELECT [VAXPServerA].DB1.dbo.getSomething(5)
----

I obtain the next error:

Msg. 207, Level 16, State 1, Line 1
The column name 'VAXPServerA' is not valid.


Any hint?

Thanks in advance

David

View 1 Replies View Related

Large Arrays, UDFs And The Text Datatype

Jul 23, 2005

I have a bunch of SPs that all rely on a UDF that parses a commadelimitted list of numbers into a table. Everything was working fine,but now my application is growing and I'm starting to approach the 8000character limit of the varChar variable used to store the list.I would like to change the UDF only and avoid having to dig through allof my stored procedures. I was hoping to use the text datatype toallow for much larger lists, but I am unable to perform anymanipulations necessary to parse the list into a table. I have triedPATINDEX, but it alone is not enough without the text maniuplations andI don't think the sp_xml_preparedocument can be used in a UDF.Anyone with any thoughts on managing large arrays in t-sql?thanks,Matt Weiner

View 2 Replies View Related

Problem With Nested Function Call (UDFs)

Jul 20, 2007

Hello Folks,I encountered a problem with SQL server 2000 and UDFs.I have a scalar UDF and a table UDF where I would like the scalar UDFto provide the argument for the table UDF like in:SELECT*FROMtransaction_tWHEREtrxn_gu_id in (select get_trxns_for_quarter(get_current_quarter( GetDate() ) ))'get_current_quarter' returns an integer which is a GUID in a tablecontaining business quarter definitions, like start date, end date.'get_current_quarter' is a scalar UDF.'get_trxns_for_quarter' will then get all transctions that fall intothat quarter and return their GUID's in a table.'get_trxns_for_quarter' is a table UDF.This doesn't seem to work at all. Regardless whether I provide thenamespace (schema) calling the scalar UDF or not. Error message isjust different.Both functions operate correctly invoked un-nested.The whole expression does work fine if I turn 'get_trxns_for_quarter'into a scalar UDF as well, e.g. by returning just one trxn_gu_id withe.g. MAX() in a scalar datatype. But of course that's no good to me.It also works fine if I select the result of 'get_current_quarter'into a variable and pass that variable into 'get_trxns_for_quarter'.But that's no good to me either since then I cannot use the wholething embedded into other SELECT clauses.Both UDF's are non-deterministic but I couldnt see how that would havean impact anyway.Never mind the syntax on that example or anyhting, I tried all theobvious and not so obvious stuff and it really seems to come down tothe fact that one UDF is scalar and the other one is not. However, Idid not come across any type of information saying that this cannot bedone.Have you any ideas?Any help would be greatly appreciated.Carsten

View 6 Replies View Related

Major Query Optimiser Weirdness With UDFs And SPs On SQL 2000

Jul 20, 2005

There is something very strange going on here. Tested with ADO 2.7 andMSDE/2000. At first, things look quite sensible.You have a simple SQL query, let's sayselect * from mytab where col1 = 1234Now, let's write a simple VB program to do this query back to anMSDE/2000 database on our local machine. Effectively, we'llrs.open sSQLrs.closeand do that 1,000 times. We wont bother fetching the result set, itisn't important in this example.No problem. On my machine this takes around 1.6 seconds and modifyingthe code so that the column value in the where clause changes eachtime (i.e col1 = nnnn), doesn't make a substantial difference to thistime. Well, that all seems reasonable, so moving right along...Now we do it with a stored procedurecreate procedure proctest(@id int)asselect * from mytab where col1 = @idand we now find that executingproctest nnnn1,000 times takes around 1.6 seconds whether or not the argumentchanges. So far so good. No obvious saving, but then we wouldn'texpect any. The query is very simple, after all.Well, get to the point!Now create a table-returning UDFcreate function functest(@id int) returns table asreturn(select * from mytab where col1 = @id)try calling that 1,000 times asselect * from functest(nnnn)and we get around 5.5 seconds on my machine if the argument changes,otherwise 1.6 seconds if it remains the same for each call.Hmm, looks like the query plan is discarded if the argument changes.Well, that's fair enough I guess. UDFs might well be more expensive...gotta be careful about using them. It's odd that discarding the queryplan seems to be SO expensive, but hey, waddya expect?. (perhaps theUDF is completely rebuilt, who knows)last test, then. Create an SP that calls the UDFcreate procedure proctest1(@id int)asselect * from functest(@id)Ok, here's the $64,000 question. How long will this take if @idchanges each time. The raw UDF took 5.5 seconds, remember, so thisshould be slightly slower.But... IT IS NOT.. It takes 1.6 seconds whether or not @id changes.Somehow, the UDF becomes FOUR TIMES more efficient when wrapped in anSP.My theory, which I stress is not entirely scientific, goes somethinglike this:-I deduce that SQL Server decides to reuse the query plan in thiscircumstance but does NOT when the UDF is called directly. This iscounter-intuitive but it may be because SQL Server's query parser istuned for conventional SQL i.e it can saywell, I've gotselect * from mytab WHERE [something or other]and now I've gotselect * from mytab WHERE [something else]so I can probably re-use the query plan from last time. (I don't knowif it is this clever, but it does seem to know when twotextually-different queries have some degree of commonality)Whereas withselect * from UDF(arg1)andselect * from UDF(arg2)it goes... hmm, mebbe not.... I better not risk it.But withsp_something arg1andsp_something arg2it goes... yup, i'll just go call it... and because the SP was alreadycompiled, the internal call to the UDF already has a query plan.Anyway, that's the theory. For more complex UDFs, by the way, theperformance increase can be a lot more substantial. On a big complexUDF with a bunch of joins, I measured a tenfold increase inperformance just by wrapping it in an SP, as above.Obviously, wrapping a UDF in an SP isn't generally a good thing; theidea of UDFs is to allow the column list and where clause to filterthe rowset of the UDF, but if you are repeatedly calling the UDF withthe same where clause and column list, this will make it a *lot*faster.

View 3 Replies View Related

Transact SQL :: Referencing UDFs And Sprocs In Linked Server

Oct 7, 2015

We have migrated a database (myDb2014) to a SQL Server 2014 instance. We have another on a 2008R2 instance (myDb2008). Both on the same server.

I have setup a linked server to the 2014 instance from the 2008R2 one.

I have a number of sprocs on myDb2008 that call TVFs and sprocs on myDb2014. This worked fine when they were both on the same instance.

Now however, I have an issue where I would have to update all the references in each calling query.

I looked into creating Synonyms but this only works for Tables/Views.

Is there a workaround to querying myDb2014 TVFs/sprocs without having to update each calling query in myDb2008?

View 25 Replies View Related

How To Find Which Stored Procs And UDFs Reference A Column

Jun 12, 2006

How can I list the stored procedures and user-defined functions that reference a given column? I could search ROUTINE_DEFINITION in INFORMATION_SCHEMA.ROUTINES for '%MyColumnName%' but MyColumnName is not always unique.

Thanks.

View 14 Replies View Related

Are Embedded Views (Views Within Views...) Evil And If So Why?

Apr 3, 2006

Fellow database developers,I would like to draw on your experience with views. I have a databasethat includes many views. Sometimes, views contains other views, andthose views in turn may contain views. In fact, I have some views inmy database that are a product of nested views of up to 6 levels deep!The reason we did this was.1. Object-oriented in nature. Makes it easy to work with them.2. Changing an underlying view (adding new fields, removing etc),automatically the higher up views inherit this new information. Thismake maintenance very easy.3. These nested views are only ever used for the reporting side of ourapplication, not for the day-to-day database use by the application.We use Crystal Reports and Crystal is smart enough (can't believe Ijust said that about Crystal) to only pull back the fields that arebeing accessed by the report. In other words, Crystal will issue aSelect field1, field2, field3 from ReportingView Where .... eventhough "ReportingView" contains a long list of fields.Problems I can see.1. Parent views generally use "Select * From childview". This meansthat we have to execute a "sp_refreshview" command against all viewswhenever child views are altered.2. Parent views return a lot of information that isn't necessarilyused.3. Makes it harder to track down exactly where the information iscoming from. You have to drill right through to the child view to seethe raw table joins etc.Does anyone have any comments on this database design? I would love tohear your opinions and tales from the trenches.Best regards,Rod.

View 15 Replies View Related

Serious Perfomance Problem Using UDFs As Function Arguments. (I Suspect A Bug, Show Me I'm Wrong!)

Nov 29, 2007


(From an exchange originally posted on SQLServer.com, which wasn't resolved...)

To return views tailored to the user, I have a simple users table that holds user IDs, view names, parameter names, and parameter values that are fetched based on SUSER_SNAME(). The UDF is called MyParam, and takes as string arguments, the name of the view in use, and a parameter name. (The view the user sees is really a call to a corresponding table returning UDF, which accepts some parameters corresponding to the user.)

But the performance is very dependent on the nature of the function call. Here are two samples and the numbers reported by (my first use of) the performance monitor:
Call to table returning UDF, using local variables:

declare @orgauth varchar(50)
set @orgauth = dbo.MyParam('DeptAwards', 'OrgAuth')
declare @since datetime
set @since = DATEADD(DAY,-1 * dbo.MyParam('DeptAwards', 'DaysAgo'),CURRENT_TIMESTAMP)
select * from deptAwardsfn(@orgauth,@since)

[187 CPU, 16103 Reads, 187 Duration]


Call to same table returning UDF, using scalar UDFs in parameters:

SELECT *
from deptAwardsFn (
dbo.MyParam('DeptAwards', 'OrgAuth')
,DATEADD(DAY,-1 * dbo.MyParam('DeptAwards', 'DaysAgo'),CURRENT_TIMESTAMP)
)
[20625 CPU, 1709010 Reads, 20632 Duration]
(My BOL documentation claims the CPU is in milliseconds and the Duration is in microseconds -- which I question.) Regardless of the unit of measure, it takes a whole bunch longer in the second case.

My only guess is that T-SQL is deciding that the parameter values (returned by dbo.MyParam) are nondeterministic, and continually reevaluates them somehow or other. (What ever happened to call by value?)

Can anyone shed some light on this strange (to me) behavior?


----- (and later, from me)---
(I have since discovered that the reference to CURRENT_TIMESTAMP in the function argument is the cause, but I suspect that is an error -- it should only capture the value of CURRENT_TIMESTAMP once, when making the function call IMHO.)

View 8 Replies View Related

Large Views Vs Multiple Small Views

Sep 6, 2007

Which is more efficient? One large view that joins >=10 tables, or a few smaller views that join only the tables needed for individual pages?

View 1 Replies View Related

Recompiling Views That Reference Other Views

Jun 28, 2007

Hello.

Newbie here. I've only been using SQL for about a year now and have some minor questions about sql objects that reference other objects.



We have some views which reference other views in the joins. I will call one the primary view and the one being referenced in the joins as the secondary view.

Recently we made changes to the secondary view.

After which the primary views which referenced it would not work because of this change and had to be 'refreshed' by using drop/create scripts which essentially just dropped it and recreated the exact same view. I do not recall the exact error message that was returned other than it seemed to suggest that it could no longer see the secondary view since it had been changed. Nothing in the primary view was changed in any way, just the secondary.



Some here where I work have suggested off hand that this was a recompile of the primary view because the contents of the secondary changed.

My questions are:

1. Exactly why did this happen and is there a proper name for it when it does?

2. The same problem does not seem to occur when we have stored procedures referencing views in the joins which had just been changed. Why is that?



Thanks for any help on the matter. I greatly appreciate it.

View 3 Replies View Related

Quicky : Views Of Views Of Views

Feb 22, 2007

Hello,

to make a report easier I'm developing it using a view of joined views of joined views.

Is there any significant performance penalty as opposed to just having one big select?

Cheers.

View 1 Replies View Related

Views Dependent On Other Views

Mar 14, 2006

Hello There,I'm trying to create a view that has calculations dependent oncalculations, where the problem resides is that each time I make acalculation I must create an intermediate view so I can reference aprevious calculation.for example lets say I have my_table that has columns a & b. now I wanta view that has a & b, c = a + b, and d = c + 1.this is grossly simplified, the calculations I actually use are fairlycomplex and copying / pasting them is out of the question.so what I have is my_view_a which makes column c, and my my_view_finalwhich makes column d (however, in my real application I have 5 of theseviews, a/b/c/d/e/)is there anyway I can consolidate all these views into one? I wasthinking of using a stored procedure with temp tables or somethingalong those lines.I just which I can use the aliases that I create for c in d in onestep.any insight would be greatly appreciated.

View 5 Replies View Related

Can Some One Help Me With SQL VIEWS

Apr 15, 2008

Hi everyone,                    I have a problem like this . I have tables Coursegroupcode, which has groupname, codeI have Courses That has Coursename, its code(group code),Term, Course Number Enrollment table which has Foreign keys Term,Course NUmber , SSN     I need to get a view like thisI should list all the coursecodes and people enrolled for each course code for selected terms  Course Table Primary keys(TERM,COUSE Number)Enrollment Table(Foreign keys) TERM ,COURSE NUMBER, SSNplease help 

View 9 Replies View Related

Sql Views

Apr 7, 2005

 Hi!
I need to know if i can build an aspx file on top of an sql view? I
can only see my tables when i connect to the database....
Collette.

View 3 Replies View Related

SQL Views

Oct 18, 2005

Can SQL Views insert to the tables they are created from?I have a database that is not well structured. It has a lot of redundency. What I want to do is create a SQL View that brings in all the data I need and have my application use that new SQL View instead of the data tables. Then I want to be able to insert new information to a SQL View that actualy gets inserted into the tables that the SQL Viewer is created from.Can this be done?Does this make any sense?

View 1 Replies View Related

Views

Mar 26, 2001

I have a query which unions the four select statements.....

the select statements are joined with other tables and views.....


When i execute the query i get ODBC timeout error........

But the strange thing is that if i execute the view individually once and again execute the query it works fine.......and later it justs works fine....

Can anyone tell why is it like that.......

Thanks,
Sajai.

View 1 Replies View Related

SP&#39;s And Views

May 23, 2000

Is there a performance hit running a sp against a view versus a base table. The view just excludes
several of the records based on some criteria, and all the data I will be retreiving is included in
the view. Or should I just stick my criteria in the SP to exclude the data?

View 1 Replies View Related

Iif Views

Jun 19, 2000

Is there a way to imbed "iif"-like logic in a SQL view? "case when" works in regular queries, but apparently is not supported in views...

View 1 Replies View Related

Views

Aug 14, 2002

I have some rather complex views to work with. Do they slow you down? Would it be better to move a view into a stored procedure? Is there any difference between these three solutions?
<B>1.Using views:</b>
Create view X
As
Select Col1, Col2, Col3 from Table1
Go

Create view Y
As
Select Col1, Col2, Col3 from Table2
Go

Create proc Z
As
Select X.Col2, X.Col3, Y.Col2, Y.Col3
From X inner join Y on X.Col1 = X.Col1
GO

<b>2.Using just a stored proc:</b>
Create proc Z
As
Select X.Col2, X.Col3, Y.Col2, Y.Col3
from
(Select Col1, Col2, Col3 from Table1) X inner join
(Select Col1, Col2, Col3 from Table2) Y on X.Col1 = Y.Col1

<b>.Joining tables</b>
Create proc Z
As
Select Table1.Col2, Table1.Col3, Table2.Col1, Table2.Col3
FromTable1 inner join Table2 on Table1.Col1 = Table2.Col1
go

Thank you!

View 1 Replies View Related

VIEWS

Aug 1, 2001

I am struggling with setting up views in SQL Server 7.0 and 2000. What types of views are available.

I have one database with 112 tables and 2308 fields.

Thanks in Advance

View 1 Replies View Related

Views

Jun 9, 2004

I have created a database connected to a GUI using VB 6.0. When editing the views from the front end, do the tables also get updated


Thanks

View 3 Replies View Related

Views ?

Aug 17, 2004

Hi,

Is there a way to create a view with read only option. i.e the view should not allow the user to perform insert, update or delete action on it.

Please advise,

Thanks,
Sam

View 1 Replies View Related

MS SQL Views

Dec 23, 2004

Is there any kind of lock on a view in ms sql database?

what happens if one of my users is looking at the view and another one is adding something to the database?

Thanks.

View 3 Replies View Related

SQL Views

Sep 26, 2005

My First time building "Views" in SQL...... I'm trying to figure out how to return a 1 instead of a two when I Count the number of records that return inn my view.

here's what I have;

SELECT TOP 100 PERCENT dbo.tbl_ProcTimesheet.idCalendar, dbo.tbl_ProcTimesheet.erNum, dbo.tbl_ProcTimesheet.PayDate,
COUNT(dbo.tbl_ProcTimesheet.TransAmt) AS Shifts, dbo.tbl_ProcTimesheet.[Employee Number], dbo.tbl_ProcTimesheet.YCode,
dbo.tbl_ProcTimesheet.XCode, dbo.tbl_ProcTimesheet.ZCode, dbo.tbl_ProcTimesheet.eeLink
FROM dbo.tbl_ProcTimesheet INNER JOIN
dbo.tbl_SysVarRestEeShiftPayCodes ON dbo.tbl_ProcTimesheet.Code = dbo.tbl_SysVarRestEeShiftPayCodes.PayCode INNER JOIN
dbo.tbl_SysVarRestEeShiftRules ON dbo.tbl_ProcTimesheet.YCode = dbo.tbl_SysVarRestEeShiftRules.YCode AND
dbo.tbl_ProcTimesheet.ZCode = dbo.tbl_SysVarRestEeShiftRules.ZCode
WHERE (dbo.tbl_ProcTimesheet.Sequence <> N'0') AND (dbo.tbl_ProcTimesheet.Week < 3)
GROUP BY dbo.tbl_ProcTimesheet.idCalendar, dbo.tbl_ProcTimesheet.erNum, dbo.tbl_ProcTimesheet.PayDate, dbo.tbl_ProcTimesheet.TransAmt,
dbo.tbl_SysVarRestEeShiftRules.DailyHours, dbo.tbl_ProcTimesheet.[Employee Number], dbo.tbl_ProcTimesheet.XCode,
dbo.tbl_ProcTimesheet.YCode, dbo.tbl_ProcTimesheet.ZCode, dbo.tbl_ProcTimesheet.eeLink, dbo.tbl_ProcTimesheet.Sequence,
dbo.tbl_ProcTimesheet.Week
HAVING ('IIf' > '1,1,0') AND ('if' > '1,1') AND (dbo.tbl_ProcTimesheet.erNum LIKE N'5648 ') AND (SUM(dbo.tbl_ProcTimesheet.TransAmt)
>= dbo.tbl_SysVarRestEeShiftRules.DailyHours) AND (dbo.tbl_ProcTimesheet.PayDate = CONVERT(DATETIME, '2005-09-06 00:00:00', 102)) AND
(COUNT(dbo.tbl_ProcTimesheet.TransAmt) > 0)
ORDER BY dbo.tbl_ProcTimesheet.PayDate, dbo.tbl_ProcTimesheet.[Employee Number]

When it counts shifts, I only want to return a maximum of i, as in either you had a shoft that day, or not. I gave up trying to figure out the "IF" string in SQL, and for the life of me I can not figure this out.

Does anyone know a good site with info on how to construct an SQL View?

View 12 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved