Replication :: Replicate Value Of A Computed Column Not The Formula

Jun 16, 2015

I'm trying to replicate client data from multiple databases into a single table. So database A, B and C replicate client data to a table in database Z. There is a settings table on A, B and C that holds the businessID and I use a function in a computed column to add this to the client table. At the moment I have just database A and Z as a test and what happens is the computed column gets replicated as a computed column with the formula. 

Can I change this so that I can replicate the computed value (at db A,B,C) of this column?

I don't really want to add a businessID to the table if possible as I'm going to need to add a number of other tables to this replication which will each need to have the businessID, a computed column would be much easier and save updating a load of scripts.

If the above is not possible is there some other solution available so I can identify which database the records came from in the table on database Z?

View 4 Replies


ADVERTISEMENT

Formula For Computed Column

Jan 17, 2007

I have downloaded the SQL Server Books online and found the section on Computed columns. In my small banking program I have columns named Deposit/Withdrawel and Balance. If I am reading this right I need to set the Computed Column Specification of my Balance Column in order to perform the calculation. My problem now is that I have no idea how to word the formula and other than telling me what a formula is the SQL Server Books online is no help whatsoever, so any help would be awesome.

If i've misunderstood what I am meant to do somebody please please tell me. Thanks

View 3 Replies View Related

Computed Column Formula

Aug 1, 2006

Is it possible to retrieve the formula associated with a computed column using t-SQL? I can use COLUMNPROPERTY( id, column, 'IsComputed') to find the computed columns, but how do I get the formula itself?

Thanks,

Mable

View 3 Replies View Related

SQL Server 2008 :: Getting Formula Of A Computed Column

May 25, 2011

I'm trying to write a query that will display the formula for a computed column in SQL Server 2008R2.

I have looked here: [URL] ....

and it say (at least I think) that I can look at the Formula property of COLUMNPROPERTY like this:

SELECT COLUMN_NAME ,
COLUMNPROPERTY(OBJECT_ID(TABLE_NAME),COLUMN_NAME,'IsComputed'),
COLUMNPROPERTY(OBJECT_ID(TABLE_NAME),COLUMN_NAME,'Formula'),
COLUMNPROPERTY(OBJECT_ID(TABLE_NAME),COLUMN_NAME,'IsDeterministic')
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Event' AND COLUMN_NAME = 'CurrentAttendance'

I know the column is computed and I can see the formula in SSMS. I wanted to do this in T-SQL. How to get this value?

View 8 Replies View Related

Computed Column - Error Validating Formula

Sep 13, 2007



I want to create a computed column with this formula:


ISNULL(NULLIF (tot_mnc, 0) / NULLIF (repl_value, 0), 0)

It works in a straight select query, but when I put it in the formula of the table design window, I get an error "Error validating the formula for column 'test_fci'"

I don't know if it's relevant but repl_value is itself a computed column with the formula:


(repl_value_e_g + repl_value_aux)

Is it possible to use the system functions in a computed column? If not, how would I pass those values into a udf and use it for the formula?

Thanks.

View 3 Replies View Related

Computed Column Referencing A Computed Column

Sep 5, 2007

Hi all,

I have a table with 3 computed columns, the first two reference a function for there value. The last computed column should be total of the other computed columns, however when trying to write the formula for this column SQL Server rejects it.

Am i correct in thinking it is not possible to reference other computed columns in a computed column's forumla.

My current work around is to call the functions again that the other computed columns use to generate the total, though this seems to me like a performance issue.

Could anyone offer some advise on my situation.

Any input apreciated.

View 1 Replies View Related

Reporting Services :: Get Computed Current Row Closing Balance Column Value In Next Row Opening Value Column

Nov 17, 2015

I have a Table Having Date,Opening,Addition,Sale values where opening value comes in the very first row other times it is zero.

In ssrs how can i have a report showing closing value = Opening+Addition-Sale  in current row (it is simple for 1st row ). this closing be the opening value in next row and same formula to be continued...

Date Opening AdditionTotalTank saleClosing Stock
01-11-15 14435 0 14435 8243 20627
02-11-15 0 15000 15000 9433
03-11-15 0 9000 9000 9436
04-11-15 0 12000 12000 8392
05-11-15 0 6000 6000 8157
06-11-15 0 12000 12000 8456
07-11-15 0 15000 15000 10903
08-11-15 0 6000 6000 8485
09-11-15 0 6000 6000 9413
10-11-15 0 21000 21000 6413

View 7 Replies View Related

Need Script To Modify A Formula Column Into Normal Column With Default Value.

Mar 29, 2001

I have a table called test with 4 fields namley studentname, Mark1, Mark2, total (formula column).

Created table test in the following structure,
create table test (studentname varchar(50), Mark1 numeric, Mark2 numeric, total as ([Mark1]+[Mark2]))

Now I need to drop formula nature of this column total and assign default value '0'. I like to know how to do it using T-Sql script.

Thanks for your help in advance.

View 2 Replies View Related

Replication Doesn't Replicate

Jul 8, 2004

Ok, I'm knee-deep in replication-hell.

I'm trying to set up snapshot replication between two SQL Server 2000 databases over the internet. Both servers run Windows 2000 server edition and SQL server 2000. The idea is to send certain local information, stored in database tables to a database from which the information is published on a website.

I've set up the distribution database (with the original name: distribution) and connected a publisher to it (let's call that one "source_database") using the sp_adddistpublisher stored procedure. No problems there...
Next step, I added a publication, the tables in source_database, and a subscriber, the website database. I've opened up port 1433 on both servers, but still it won't send anything from the source_database to the website database....

It gives no errors, but just doesn't do anything...
Now, I've looked for possible problems and I think these problems might be able to cause problems:
- The initial snapshot is not reaching the subscriber
- I've made a push subscription which may has to become a pull subscription
- The RPC's aren't available, because both servers are highly secured
- The wrong serverpack is installed (this one is a wild guess)

Does anybody have any idea on how I can get my distribution working or solve any of the problems above, cause I'm running out of idea's....
(P.S. I'm a bit of a noobie to replication, I've set it up in a test environment before and it just worked perfectly, but the real thing isn't)

View 4 Replies View Related

SQL Server Replication Error - Not Able To Replicate On Subsriber.

Jan 19, 1999

I am having two NT/SQL Server 6.5 and i tried to replicate the database on SQL Server from One Server to another Server.
When i try to replicate from Server A[Publisher] to Server B[Subscriber] it is giving error on Distribution History Log on Manage Scheduled Task Dialog.
The Error is like this :
08001 [ODBC SQL Server Driver] [dbnmpntw] ConnectionOpen (Createfile()).

and it is trying again and again by using retry option.

Kindly guide me by mentioning the reason for this error.

Email to : rsraja@sfl.soft.net

Regards
R. Suseendran Raja.

View 1 Replies View Related

SS2005 Replication: Can You Replicate Constraints Without Reinitializing?

Jan 11, 2007

We have a two SQL Server 2005 databases set up using Transactional Replication. My manager has asked me to set it up to replicate constraints (default, fk, et) on the tables in the main publication. I said sure, I can do it, but I will have to re-initialize the subscription. He said there was a way to do it without re-initializing the subscription. I cannot find anything in my research to indicate that there is a method to do so (via call sp_ functions, etc). Is it indeed possible to replicate constraints on replicated tables without re-initializing the who subscription? The reason he does not want me to perform a re-initialization is that we are a few weeks before moving into production, and a full re-initialization takes 1.5 days, which would impact system availability.

Thanks in advance for any advice.

View 1 Replies View Related

Replication :: Unable To Replicate A View Or Function

Nov 13, 2015

I have some issue when replicating a view (transactional replication).I have following objects on publisher:

Table: [Metadataschema].[Entity]
View: [dbo].[EntityLogicalView]
the view definition is:

create view [dbo].[EntityLogicalView] as (SELECT * FROM [Entity] WHERE OverwriteTime = 0)

this is what I get when I run "Script View as Create". The same query is used by the replication.Unfortunately this query fails on the subscriber "Unable to replicate a view or function because the referenced objects or columns are not present on the Subscriber". I cannot even runt his query manually on the subscriber, it only works when I change it like this:create view [dbo].[EntityLogicalView] as (SELECT * FROM [Metadataschema].[Entity] WHERE OverwriteTime = 0) Is there any way to get this working? Can I change the creation scripts used by the replication or force publisher to include schema names in all objects?

View 5 Replies View Related

Transactional Replication Setup To Replicate Views

Mar 20, 2007

Hello,

I setup the transactional replication to replicate remote database that has 50 tables.

Two of the tables with huge columns.

I splitted the columns by creating several views before running the initial snapshot.

Questions:

1. Can the database replication copy the views.?

2. Where the view will be stored at the subscriber database?

Thank you.

Edwin

View 3 Replies View Related

Replication Invalid Syntax Error: Table Has Computed Primary Key

Sep 13, 2006

Hi,

I have set up a publisher using transactional replication. ( all seems ok). The initial snapshot has been generated.

The replication share on the distributor has all the generated DDL in it.

I add a subscriber. The tables are generated up to tblCountry then I get an incorrect syntax near ')' error

The Replication Monitor shows the following code as the cause. ( bold indicates incorrect sql)

Is this a bug in Replication (as this is an autogenerated sp)or have I configured something incorrectly?



The ddl for the table index is as follows ( from the replication folder)



/----

CREATE TABLE [APP].[tblCountry](
[CountryId] AS ([ISO 3166-1 NUMERIC-3]) PERSISTED NOT NULL,
[CountryCode] AS ([ISO 3166-1 ALPHA-2]) PERSISTED NOT NULL,
[CountryName] [varchar](80) COLLATE Latin1_General_CI_AS NOT NULL,
[ISO 3166-1 ALPHA-2] [char](2) COLLATE Latin1_General_CI_AS NOT NULL,
[ISO 3166-1 ALPHA-3] [char](3) COLLATE Latin1_General_CI_AS NOT NULL,
[ISO 3166-1 NUMERIC-3] [int] NOT NULL
)

GO

---/

/------ Keys ddl (.dx)

ALTER TABLE [APP].[tblCountry] ADD CONSTRAINT [PK_TBLCOUNTRY] PRIMARY KEY CLUSTERED ([CountryId])
go
ALTER TABLE [APP].[tblCountry] ADD CONSTRAINT [UQ_TBLCOUNTRY_ALPHA2] UNIQUE NONCLUSTERED ([ISO 3166-1 ALPHA-2])
go
ALTER TABLE [APP].[tblCountry] ADD CONSTRAINT [UQ_TBLCOUNTRY_ALPHA3] UNIQUE NONCLUSTERED ([ISO 3166-1 ALPHA-3])
go
ALTER TABLE [APP].[tblCountry] ADD CONSTRAINT [UQ_TBLCOUNTRY_COUNTRYNAME] UNIQUE NONCLUSTERED ([CountryName])
go


--------/

/------------

Command attempted:


create procedure "sp_MSins_APPtblCountry_msrepl_ccs"
@c1 int,@c2 varchar(80),@c3 char(2),@c4 char(3),@c5 int
as
begin
if exists ( select * from "APP"."tblCountry"
where
)
begin
update "APP"."tblCountry" set
"CountryName" = @c2
,"ISO 3166-1 ALPHA-2" = @c3
,"ISO 3166-1 ALPHA-3" = @c4
,"ISO 3166-1 NUMERIC-3" = @c5
where
end
else
begin
insert into "APP"."tblCountry"(
"CountryName"
,"ISO 3166-1 ALPHA-2"
,"ISO 3166-1 ALPHA-3"
,"ISO 3166-1 NUMERIC-3"
)
values (
@c2
,@c3
,@c4

(Transaction sequence number: 0x00000016000004F2014500000000, Command ID: 213)

------------/

View 5 Replies View Related

PK On Computed Column

Aug 3, 2004

Maybe I am missing something very obvious, but I couldn't do it: begin trangocreate table foo (f1 int not null,f2 int not null,f3 as (f1 + f2) not null primary key clustered)gorollback trango This returns:Server: Msg 8183, Level 16, State 1, Line 8Only UNIQUE or PRIMARY KEY constraints are allowed on computed columns.

View 4 Replies View Related

Computed Column?

Apr 5, 2008

i have a table that contains 2 columns

A B (B values are only 1 and 2)
-- --
x 1
y 2
z 1
x 2
z 1
j 1
k 2

i want to make a query that will check for dinstinct x what B values it has Ex. It will show result like this

result
A B
-- --
X 1 and 2
Y 2
z 1
K 2

how to make please help

View 2 Replies View Related

Computed Column

Feb 16, 2007

I want to create computed column in table.
Suppose I have three physical column A,B and C
I want to create compute column with computed column.
A+B= X
X+C=Z
Is it possible.

View 2 Replies View Related

Computed Column

Jul 20, 2005

I created a index on a computed column. I did not see any improvementin performance with a join to this column and also my inserts andupdates to this table are failing. Any ideas?Chender

View 2 Replies View Related

Computed Column

May 22, 2008



Hi,

i have to use a datetime field in all the tables in a database as a updated timestamp.
i.e. : whenever an update happens to a row in a table, this column called LASTUPDATED has to be updated with current date time.Is there any way to implement this without using the trigger ?
can i use COMPUTED column to acheive this ?

Please help me..thnks in advance..

View 2 Replies View Related

Merge Replication Replicate Master And Related Tables

Jan 19, 2007



hi all,

Could we configure a merge replication such as replicate the master table and its all related tables (relation deep could be 1.)

We dont want to manually find master table relations and configure replication for the related tables.

please help for that configuration

kinds

View 5 Replies View Related

Replication :: Replicate DDL Setting Is Not Working If Multiple Subscribers Are Used

Oct 22, 2015

Replicate ddl setting is not working if multiple subscribers are used...

View 2 Replies View Related

Replicate Ntext Text Image In Transaction Replication

May 16, 2007

Hi!

i have a problem with my replication.

I have two SQL 2005 SP2 Server and want to use the transaction replication with updateable subscriber. Now the problem is that i can do any changes on the master server. But if i want to change a record on the subscriber which contains a ntext, text, oder image column - then i geht the error that the field will be NULL on the master.



Is there any solution to fix this problem? I dont wan`t to change the datatype vom ntext to varchar(max) !!



greetings

Holger

View 3 Replies View Related

Formula Column.

Jul 20, 2005

HI,I have a problem in formula column.I have 8 1 bit varibles in a tablefor ex: Flag1, falg2, flag3 ...Flag8Now I want to create another variable as a small integer and copy allthe flgas to that field.For ex:(flag1 << 0x80) | (flag2 << 0x40) | ..... | flag8I tried all possible ways?Let me know how to write the formula for this column.Thanks,Venkat.

View 1 Replies View Related

Formula Column

Jul 20, 2005

Hi,I would like to create a calculated column using the formulasection for a table. I am having some trouble doing this.The table's name is ReportParameter. The calculated column's name istbcalculatedcolumn and tb1 and tb2 are boolean columns in the table.I would like to use an If then statement such as the following (inpsuedo code):If tb1 = 1 then tbcalculatedcolumn = 1Elseif tb2 = 1 then tbcalculatedcolumn = 2EndifThanks for the help,Bill

View 6 Replies View Related

Computed Column Question

Jun 25, 2007

I have a SQL table that maintains a field on the status of a report being completed.
I have in the record the date the report is due (DateDue)
I also have a field called DaysLate which I have set to be a calculated field with formula:
DATEDIFF(dd, DateDue, GETDATE())
Thsi works but when the report is *not* late I'd like this to be null  is there I way I can do this conditional calculation in a calculated field?
Regards
Cvive

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

Altering A Computed Column?

Feb 27, 2008

somehow I am not able to figure this out.

How do I change a computed column using the ALTER TABLE ALTER COLUMN... command?

View 1 Replies View Related

Computed Column Issue

May 19, 2008

Hi,

I'm having a problem with a computed field in a table. I have a stored procedure that inserts a row into a table and returns the id and the computed value.
The computed colmn is returned as a decimal (29,6) but for some reason the value is returned with no decimals (confirmed by the Profiler).
The value is calculated and displayed in the database properly with decimals. Also, Is Persisted is OFF.

Below is the stored procedure, computed column foruma (both give same result), and the profiler trace.

Thanks

Stored Procedure
================================================== ==============
ALTER PROCEDURE [Purchasing].[ntp_PurchaseOrderDetail_Insert]
(
@PurchaseOrderDetailId int OUTPUT,
@PurchaseOrderId int ,
@OrderQty decimal (11, 4) ,
@VendorProductId int ,
@Description nvarchar (255) ,
@UnitPrice decimal (18, 6) ,
@PackingQty decimal (14, 4) ,
@DueDateValue nvarchar (50) ,
@ModifiedDate datetime ,
@IsUnitPriceManual bit ,
@LineTotal decimal (29, 6) OUTPUT
)
AS
INSERT INTO [Purchasing].[PurchaseOrderDetail]
(
[PurchaseOrderID]
,[OrderQty]
,[VendorVendorProductID]
,[Description]
,[UnitPrice]
,[PackingMethod]
,[PackingQty]
,[DueDateValue]
,[ModifiedDate]
,[IsUnitPriceManual]
)
VALUES
(
@PurchaseOrderId
,@OrderQty
,@VendorVendorProductId
,@Description
,@UnitPrice
,@PackingMethod
,@PackingQty
,@DueDateValue
,@ModifiedDate
,@IsUnitPriceManual
)

-- Get the identity value
SET @PurchaseOrderDetailId = SCOPE_IDENTITY()

-- Select computed columns into output parameters
SELECT
@LineTotal = [LineTotal]
FROM
[Purchasing].[PurchaseOrderDetail]
WHERE
[PurchaseOrderDetailID] = @PurchaseOrderDetailId


Computed Column Formula
================================================== ==============
isnull(CONVERT(DECIMAL (29,6),[OrderQty]*([UnitPrice]*[PackingQty])),0.000000)
or
isnull([OrderQty]*([UnitPrice]*[PackingQty]),0.000000)

Profiler Trace
================================================== ==============
declare @p1 int
set @p1=115
declare @p16 numeric(29,0) <- should be numeric(29,6)
set @p16=5 <- value should be 5.259200
exec Purchasing.PurchaseOrderDetail_Insert @PurchaseOrderDetailId=@p1 output,@PurchaseOrderId=68,@OrderQty=4,@VendorProd uctId=28,@Description=N'93678975 - GL-2222',@UnitPrice=0.657400,@PackingMethod=N'Bags (2)',@PackingQty=2.0000,@DueDateValue=NULL,@Modifi edDate=''2008-05-19 15:06:37:610'',@LineTotal=@p16 output
select @p1, @p16

View 2 Replies View Related

Using Computed Column Specification

Dec 13, 2012

I have a question about Computed Column Specification which you can specify as a formula for each column inside a table.

I have now columns named Age and Class.

Classes are "Kids" (ID #1) , "Junior" (ID #2) and "Senior" (ID #3)
Kids, which is for age of 6 till 12
Junior, which is for 12 till 16
Senior, 16 and above.

I have already searched for hours (I really did) on the internet for a solution, but ended with more questions because of the complicated solutions.

Now the Age is shown as a result of a formule of DOB (Date of Birth column), now I want the exact same thing, but the age must specify which Class the user is in.

Example, when I add a user with the birthdate 25/03/1988 (DD/MM/YYYY) he/she gets 24 as age.

With this formula : (datediff(year,[age],getdate()))

Now I want that the user gets "Senior" as Class (same table).

Senior is ID 3 in this case.

Now I do know how Case, When and Then works, but the validation fails. After reading some forums I understood that I should use a create function method. I am not really experienced with creating functions. Also the coding looks more different as I am used to. How to link the Computed Column to a created formula.

View 3 Replies View Related

Using Computed Column In The Query

Apr 14, 2004

need help ,

i have a table called "Loans" where i need to compute a column i.e. NoofDays based on which other calculation like interest calculation needs to be done.
my query goes like this

"select datediff(dd,VDate, MDate) as NoOfDays ,NoOfDays * Principal * Rate /100 * 365 from Loans".

if i run the above query it says

"Invalid column name 'NoOfDays'".

this executes fine if i use Access but not in SQL Server.

can anybody say what might be the problem and how i can solve it.

regards

Rajesh :)

View 1 Replies View Related

Problem With Computed Column

May 19, 2008

hi
i want to create a table that has a computed column like this :
create table resources(
id int identity(0,1) primary key,
currentDate int not null,
currentMonth int default 0,
monthBefore as (currentMonth - (select top 1 currentMonth from resources where (currentDate - resources.currentDate) = 1)))

as u can see, monthBefore is computed column, and i want get currentMonth value of previous month, for this work, i define a column as currentDate that hold only year+month (like 971,082,083,...) and by this expression, i want to get currentMonth of previous record (previous month), but the following error has shown me :
Subqueries are not allowed in this context. Only scalar expressions are allowed.
how to solve this problem to get currentMonth of previous record ?
thanks

View 3 Replies View Related

Null And Computed Column

Oct 1, 2007

how do you change the allow null on a column to be 0,
so instead of having null when empty, it would be 0,
I tried default value or binding to 0 to -1, and to 1
and in 0 or -1, it stays null, in 1 it puts the 1
for example if is quantity, it puts as if I would have 1 quantity,
so it's either null, or whathever number I put visides -1 or 0
how can I make it be 0 as defult?
I'm using it to add and substract with computed column, formula;
and the problem is that if it's the first time it's used it does not add or substract, becsause it does not add null with a number, if it has 0 than it works,
whata I had to do is add it manually, but of course it doesn't suppoesed to be that way
any suggestions will be appriciated:

View 2 Replies View Related

Computed Column Calculations

Jul 23, 2005

If i want to split a computed column into two or more columns based onthe the length (its a varchar) of the computed column, how often willsql server determine what the computed column is? roughly along thelines ofselect comp_col,'comp_col 2'=case when datalength(comp_col)<=100 then comp_colelse left(comp_col,99) + '~' end,datalength(comp_col)from aTableAs you can see, in this scenario we use the computed coulumn,comp_col, in a few places, so does SQL server need to calculate thiseach time? I'm playing with this on the basis that it does and thustrying to shift the computed column out to a variable and thenmanipulte and return from their, but that has its own problems whenyou throw in additional parameters (trying to join table udf's) so ifSQL server is smart enough to not calculate the column each time Iwould save a lot of hassle?Cheers Dave

View 9 Replies View Related







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