Create View With Computed Columns?

Apr 1, 2015

I have a table that I cannot allow a computed field to exist on (due to a 3rd party software), so I am thinking I could create a view with a computed field that is persistent, is that possible?

the syntax below will not work, I am not even sure if this is possible, but if it can work, that would be great.

I am wanting to get the sum of jetfoot1, 2 & 3 and have the total added up as "total"

create view ViewSumReport as
select JETFOOT1,JETFOOT2,JETFOOT3,(JETFOOT1+JETFOOT2+JETFOOT3)as [total] persisted
from dbo.fielddata
GO

View 2 Replies


ADVERTISEMENT

Write A CREATE VIEW Statement That Defines A View Named Invoice Basic That Returns Three Columns

Jul 24, 2012

Write a CREATE VIEW statement that defines a view named Invoice Basic that returns three columns: VendorName, InvoiceNumber, and InvoiceTotal. Then, write a SELECT statement that returns all of the columns in the view, sorted by VendorName, where the first letter of the vendor name is N, O, or P.

This is what I have so far,

CREATE VIEW InvoiceBasic AS
SELECT VendorName, InvoiceNumber, InvoiceTotal
From Vendors JOIN Invoices
ON Vendors.VendorID = Invoices.VendorID

[code]...

View 2 Replies View Related

Create A View That Counts In One Of The Columns?

Nov 5, 2014

I need to create a view that counts in one of the columns.

The tricky part for me is that it should only count to three, then start on 1 again and count to three again.

Example

1 - car
2 - bike
3 - Motorbike
1 - Boat
2 - Airplane
3 - Motorboat
1 - Bicycle

View 4 Replies View Related

Computed Column Of A View

Jun 11, 2003

I have a view that has 2 columns. The first column is associated with a function for the Units. The second column calculates the Market Value:

View
====
Col1: Unit = get_number_of_units()
Col2: MV = get_number_of_units() * get_unit_value()

I need to call get_number_of_units() twice in the view. Is it possible to changes Col2 to something like: MV = Col1 * get_unit_value()?

Is get_unit_value() being called if I do Select Col1 from View?

Thanks.

View 1 Replies View Related

Partitioned View With Computed Column

Jan 23, 2008

Using SQL Server 2005. Defined partitioned view with computed column. Computed column was a constant varchar. Ran a SELECT. According to Query Execution Plan, SQL did recognize the computed column as the partitioning column and used it to optimize the query.

However MSDN says a computed column cannot be used as the partitioning column.

Could someone from MS clarify?

View 2 Replies View Related

Partitioned View && Computed Column..

May 14, 2006

Hello,

please enlighten me regarding an issue with partitioned view... There are 3 tables in my DB of a similar structure:

CREATE TABLE Table1 (value1 varchar(1))
CREATE TABLE Table2 (value1 varchar(1))
CREATE TABLE Table3 (value1 varchar(1))

INSERT INTO Table1 (value1)
SELECT 'a' UNION SELECT 'b' UNION SELECT 'c'

INSERT INTO Table2 (value1)
SELECT 'a' UNION SELECT 'b' UNION SELECT 'c'

INSERT INTO Table3 (value1)
SELECT 'a' UNION SELECT 'b' UNION SELECT 'c'

As sometimes we need to access all data from these tables, a view has been created:

CREATE VIEW AllData AS
SELECT value1, '1' as table_id from Table1
UNION ALL
SELECT value1, '2' as table_id from Table2
UNION ALL
SELECT value1, '3' as table_id from Table3

The problem is that while running a query like

SELECT * from AllData WHERE value1 = 'a' and table_id = '3'

I see a table scan being performed on all 3 tables, not just table3 - i.e optimisation engine doesn't care for my table_id computed column and for that fact that required data is located ONLY in Table3.

Is there any way to force optimiser to consider this column andrrebuild a plan? If not - how can I rebuild a view (I can't modify tables) to achieve that? Maybe create an index for a view?

Thanks in advance. RTFM and search don't seem to clarify this for me...

View 8 Replies View Related

Computed Columns

Jul 4, 2007

Is it possible to get a Computed column in one table to carry out a SELECT & SUM from a column in another table?  I have tried a SELECT / FROM / WHERE construct but SQL complains about that.
Regards
Clive

View 3 Replies View Related

Computed Columns...

May 20, 2008

I am working with data that has a lot of records that get updated and inserted frequently, and to avoid having to create formulas through code all over the place, I am experimenting with computed column formulas. I have a question though.. It works well for any addition or subtraction (columnA+columnB), however, when I try to use division (columnA/columnB), it only returns integers, no decimals. I would like to have decimals, particularly with a specific scale and precision and I would really like to attempt this without any coding. Any suggestions? 

View 3 Replies View Related

Computed Columns

Oct 31, 2003

I have a table with fields called fname (First Name) and lname (Last Name). I need the userīs email thai is compose from lname and fname:
LOWER(LEFT (fname,1) + lname)

Is there any difference between creatig this computed column ia a table or in a view in SQL Server 2000?

I can do:

1. CREATE TABLE Users(
fname varchar(20),
lname varchar(20),
email as LOWER(LEFT (fname,1) + lname) )

Or

2. CREATE TABLE Users (
fname varchar(20),
lname varchar(20))

CREATE VIEW Vw_users (fname, Lname ,
email)
AS
SELECT fname, Lname ,
LOWER(LEFT (fname,1) + lname) )


Is one of them is better?

Paulo

View 6 Replies View Related

Computed Columns

Nov 6, 2006

Dear all,
Pls help me with this
I have 2 tables
Trip (TripID, Duration)
Reserve(ReserveID, TripID, StartDay, EndDate)
in which EndDate = StartDay + Trip.Duration
How can I do this?

View 3 Replies View Related

Computed Columns

Jul 20, 2005

I have a table with fields called fname (First Name) and lname (LastName). I need the userīs email thai is compose from lname and fname:LOWER(LEFT (fname,1) + lname)Is there any difference between creatig this computed column ia a tableor in a view in SQL Server 2000?I can do:1. CREATE TABLE Users(fname varchar(20),lname varchar(20),email as LOWER(LEFT (fname,1) + lname) )Or2. CREATE TABLE Users (fname varchar(20),lname varchar(20))CREATE VIEW Vw_users (fname, Lname ,email)ASSELECT fname, Lname ,LOWER(LEFT (fname,1) + lname) )Is one of them is better?Paulo*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!

View 1 Replies View Related

Computed Columns

Sep 25, 2006

Hi,

Consider the following example

create table sample

(col1 int,

col2 int ,

col3 AS col1 + col2) PERSISTED NOT NULL)

basically col3 is a computed column. Now when ever a row in col1 or col2 is updated the computed column will reflect the new value. how does this happen in the background. does this use row level triggers or what other mechanism is used to maintain col3 - computed column

View 9 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

Computed Columns And Constant

Aug 22, 2006

Hi, I have a small problem with my database. I've got following situation: I have a computed column, which value is base on currency rate: rent * rate. Users have to have possibility to change currency rate easily (maybe another table or constant). Is there any way to create formula, which would compute value properly, via constant or something like this? Or the easiest workaround would be load data into dataset (I'm building asp.net application - database will be very small - couple of hundreds of records) and make calculations programmatically?

Przemek

View 1 Replies View Related

Modify Computed Columns Using T-SQL

Oct 8, 2007

Hi,
I have a table with 4 columns let us say A,B,C,D.
column D is computed column with formula A + '-' + B
Now, i want to add one more condition to the formula which looks like "A + '-' + B + '-' + C".

Please let me know how to do this using T-SQL as i cannot open the table in design mode in production server.

Thanks in Advance!!

View 12 Replies View Related

Smalldatetime In Indexed Computed Columns

Nov 13, 2001

i have a table containing the column "current month" and "current day" as smallint which contains the number of months since 1900-01-01 and the day of this month. now i want to trnslate this column in a smalldatetime ( not datetime !) value using a computed column and then create an index on that column.

the formula should be:
dateadd(d,[current day]-1,
dateadd(m,[current month],convert(smalldatetime,'1900-01-01'))
)

trying to create an index on this column results in an error message saying
that the formula is nondeterministic or imprecise

removing the convert statement leaving only the date results in a column of type datetime and creating the index works fine


replacing convert(smalldatetime,'1900-01-01') with a column name which has the type smalldatetime also allows to create an index but thats not what i want to do.

it seems that sql2000 thinks a convert from a string to a date is nondeterministic. Is there any possibility to create a const of type smalldatetime without using convert?

Any idea?

(besides this, datediff(d,'yyyy-mm-dd',anydate) is nondeterministic but datediff(d,dateadd(d,0,'yyyy-mm-dd'),anydate) is deterministic. strange...)





and

View 1 Replies View Related

Computed Columns In Temp Tables

Jun 25, 2004

I am having a problem with using UDF as part of a temp table computed column. Here's the sample code:
IF EXISTS( SELECT 1 FROM information_schema.routines WHERE routine_name = 'fn_test')
DROP FUNCTION dbo.fn_testGO
CREATE FUNCTION dbo.fn_test( @x int, @y int)
RETURNS INT AS
BEGIN
DECLARE @z INT
SET @z = @x + @y
RETURN @z
END
GO

CREATE TABLE #X
(
x INT,
y INT,
z AS (dbo.fn_test(x,y))
)
I receive the following error:

Server: Msg 208, Level 16, State 1, Line 2
Invalid object name 'dbo.fn_test'.

I do not get this error if I use a regular table.
HELP!

View 5 Replies View Related

T-SQL (SS2K8) :: Computed Columns - Max From Other Column For The Same ID?

Jul 25, 2012

Suppose a table being

Create table myTable (ID int, col1 int, col2 int)

I know how to make a computed column being the sum of other column for the same ID e.g. "computed_column = col1 + col2".

Getting the average would be "computed_column = (col1 + col2)/2" But how to get the Max, Min?

Even "Sum(col1,col2)" or AVG(col1, col2) does not work as the formula for a computed column...

View 9 Replies View Related

Computed Columns Asynchronously Updating?

Mar 19, 2008

I have a checksum calculation as a persisted, indexed computed column on a temporary table that I used to compare against original records to detect changes.

It seems that the update/ insert statements in my procs get out of sync on larger tables (500,000 rows +) with the checksum calculations. The only thing I can think of is that the column calculations are performed asynchronously in relation to the updates/ inserts. This is a problem for me.

Is my assumption correct? If it is, how can I adjust for this, i.e., force the computations to be performed synchronously or wait for the computations to complete before running comparisons?

-Jeremy

___________________________
Geek At Large

View 1 Replies View Related

Table Size And Computed Columns

Jul 23, 2005

In SQL Sever, do the size of computed columns gets added to the totalsize of the tables? Does SQL server stores the actual values incomputed columns?Thanks_GJK

View 1 Replies View Related

Trying To Find A Match In Computed Columns

May 26, 2006

I need to create an function similar to the "MATCH" function in Excelthat evaluates a number within a set of numbers and returns whetherthere is a match. I have put the example of what I see in excel in thecheck column. The "0" answer in the result column is in the fourthaccount in the list. Somehow I need to loop through the accountscomparing the result to the total and indicate a match in the checkcolumn. It wouldn't even need to tell me the row number; it could be a0 or 1.account total result check123770266.84124.2112377026131.050 412377026164.38-33.33123770260131.051237702678.7152.3412377167-31.34221.891237716731.34159.211237716738.55152 51237716731.34159.211237716715238.5512377167490.91-300.36123771670190.55123771670190.5512377167-31.3443.341237716731.34-19.341237716738.55-26.551237716731.34-19.3412377167152-14012377167490.91-478.9112377167012123771670121237736347.058412377363131.05012377363-45.38176.4312377363-47.05178.11237736347.0484.0112377363-47.04178.091237736347.058412377363541.11-410.06123773630131.0512377363672.15-541.11237750737.64152.91

View 3 Replies View Related

Computed Columns Asynchronously Updating?

Mar 19, 2008

I have a checksum calculation as a persisted, indexed computed column on a temporary table that I used to compare against original records to detect changes.

It seems that the update/ insert statements in my procs get out of sync on larger tables (500,000 rows +) with the checksum calculations. The only thing I can think of is that the column calculations are performed asynchronously in relation to the updates/ inserts. This is a problem for me.

Is my assumption correct? If it is, how can I adjust for this, i.e., force the computations to be performed synchronously or wait for the computations to complete before running comparisons?

View 4 Replies View Related

Computed Columns Used In Select Statement

Nov 12, 2007

Does tsql allow sth like

Select col1*col2 as ComputedColumn, ComputedColumn + 2 as NewColumn
From T_Table

THis is possible in Access.

View 5 Replies View Related

Simple Question About Computed Columns

Aug 30, 2007



Hello,
does anyone know a website, where I can read something about the syntax of Computed Columns?
I don't know how to enter the following expression in the computed columns field of MS SQL Server:

When x-y < 0 Then 0 else x-y

Thank you
M-l-G

View 3 Replies View Related

OLE DB ARITHABORT Error With Indexed Computed Columns

Oct 31, 2002

Instead of using Full-Text indices, which I don't like to manage, we've tried to use seperate tables that contain recordID, the word, a count of the word in the parent field and computed column which is the CHECKSUM() of the word column. I indexed the checksum column with a clustered index.

Works great in Query Analyser. But when the ASP page calls it, I get this message:

Microsoft OLE DB Provider for SQL Server (0x80040E14)
INSERT failed because the following SET options have incorrect settings: 'ARITHABORT'.

Same for updates and deletes. The question is how should these SET settings be done? Any ideas would be greatly welcomed.

Thanks
Jason

View 3 Replies View Related

Bulk Inserting Into Table With Computed Columns

Jul 20, 2005

Using SS2K, I'm getting the following error while bulk inserting:Column 'warranty_expiration_date' cannot be modified because it is acomputed column.Here is my bulk insert statement:BULK INSERT dbo.TestDataFROM 'TestData.dat'WITH (CHECK_CONSTRAINTS,FIELDTERMINATOR='|',MAXERRORS = 1,FORMATFILE='TestData.fmt')The computed column is not referenced in the format file and the data filedoes not contain the computed data.Thanks

View 2 Replies View Related

HOW TO CREATE NON CLUSTERED INDEX On Computed Fied

Apr 8, 2008

hi all ,
I am using sql server 2005.
I want to create non clustered index speed up the query search.
but when i create index with this code
CREATE UNIQUE NONCLUSTERED INDEX TEST ON DOCTOR_MASTER( DR_CUST_DOCTORCODE)

i am getting error like
Column 'DR_CUST_DOCTORCODE' in table 'DOCTOR_MASTER' cannot be used in an index or statistics or as a partition key because it is non-deterministic.

This column is formulated column whose value is populated when record get inserted through function. It values is i format identity column value + category

Pleasse suggest.

View 2 Replies View Related

Matching A View's Columns To It's Underlying Table's Columns

Jul 20, 2005

Hello,Using SQL Server 2000, I'm trying to put together a query that willtell me the following information about a view:The View NameThe names of the View's columnsThe names of the source tables used in the viewThe names of the columns that are used from the source tablesBorrowing code from the VIEW_COLUMN_USAGE view, I've got the codebelow, which gives me the View Name, Source Table Name, and SourceColumn Name. And I can easily enough get the View columns from thesyscolumns table. The problem is that I haven't figured out how tolink a source column name to a view column name. Any help would beappreciated.Garyselectv_obj.name as ViewName,t_obj.name as SourceTable,t_col.name as SourceColumnfromsysobjects t_obj,sysobjects v_obj,sysdepends dep,syscolumns t_colwherev_obj.xtype = 'V'and dep.id = v_obj.idand dep.depid = t_obj.idand t_obj.id = t_col.idand dep.depnumber = t_col.colidorder byv_obj.name,t_obj.name,t_col.name

View 2 Replies View Related

Problems On Create Proc Includes Granting Create Table Or View Perissinin SP

Aug 4, 2004

Hi All,

I'm trying to create a proc for granting permission for developer, but I tried many times, still couldn't get successful, someone can help me? The original statement is:

Create PROC dbo.GrantPermission
@user1 varchar(50)

as

Grant create table to @user1
go

Grant create view to @user1
go

Grant create Procedure to @user1
Go



Thanks Guys.

View 14 Replies View Related

Grant CREATE VIEW, CREATE PROCEDURE ...

Apr 12, 2006

Hi,

I have currently a problem with setting up the permissions for some developers. My configuration looks like this.

DB A is the productive database.

DB B is a kind of "development" database.

Now we have a couple of users call them BOB, DAVID, ...

who are members of the db role db_reader and db_writer for the productive db a but they should be allowed to do nearly everything on db b.

Therefor I added them to the db role db_owner for db b.

For testing purposes I tried to "CREATE" a view TEST as BOB in database B but I received the error message

'Msg 262, Level 14, State 1, Procedure Test, Line 3

CREATE VIEW permission denied in database 'b'.'

I cross checked the permissions on db level and I even granted all available permissions on db level but nevertheless I receive this error message.

What's my mistake?

Of course it worked fine when I give them sysadmin rights but then they have far too much permissions.

Regards,

Stefan

View 8 Replies View Related

Alter View / Create View

Aug 14, 2000

I had given one of our developers create view permissions, but he wants to also modify views that are not owned by him, they are owned by dbo.

I ran a profiler trace and determined that when he tries to modify a view using query designer in SQLem or right clicks in SQLem on the view and goes to properties, it is performing a ALTER VIEW. It does the same for dbo in a trace (an ALTER View). He gets a call failed and a permission error that he doesn't have create view permissions, object is owned by dbo, using both methods.

If it is doing an alter view how can I set permissions for that and why does it give a create view error when its really doing an alter view? Very confusing.

View 1 Replies View Related

New View Not Showing Columns

Jul 9, 2001

Any idea why I cannot see (in Enterprise Manager) all the coulmns of a selected table? All I get is * all columns - not each one, meaning I cannot select individual columns in my new view. Could it be the version? I am running SQL 7.0 SP1

Thanks

View 2 Replies View Related

View Columns Switched

Nov 24, 2005

I'm having an odd issue with SQL Server. What happens is the following: I create view1. I then create view2 which uses view1. I then create view3 which uses view2. Then, if I make a change in View1, my other views are messed up. What happens is that columns in view3 (and view2) will be switched. Therefore, if a crystal report for example references view3, I'll suddenly get an exception due to a field in the cyrstal report thinking it's going to get an integer but gets a date instead. It's as if the columns were moved around. Is this a known issue with SQL Server 2000? Has someone else had that here? Has someone resolved that here? thx.

View 2 Replies View Related







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