How to set NULL values inside VB Script .Net? Both causes error:
.FECHAAP = NULL
.FECHAAP = System.DBNull
.FECHAAP = Nothing
-Jamie
|||ThanksHow to set NULL values inside VB Script .Net? Both causes error:
.FECHAAP = NULL
.FECHAAP = System.DBNull
.FECHAAP = Nothing
-Jamie
|||ThanksI get negative values for percentage calculation in a MDX query. The MDX query has a crossjoin between two sets containing calculated members from the same dimension, one of the calculated members being a percentage value. I'm not sure why some of the percentage values are negative.
Another problem I'm facing is that the percentage value is not being displayed as per the FORMAT_STRING property, in my Reports in Reporting Services 2005 that use the data generated by the MDX query.
Any help or suggestion is appreciated.
Hi. Can we see the MDX query you're using and a small data sample which provides the negative percentage?
PGoldy
|||Hope this will give you an idea:
WITH
MEMBER [ITEMA].[ITEMA].itemmember
as
' (ITEMA.ITEMA.&[itemmember], [Measures].[NUMBER]) '
MEMBER [ITEMA].[ITEMA].TOTAL
as
' SUM(ITEMA.ITEMA.Members, [Measures].[NUMBERS]) '
MEMBER [ITEMA].[ITEMA].ITEMPERC
as
' Iif(IsEmpty([ITEMA].[ITEMA].TOTAL),0,([ITEMA].[ITEMA].itemmember / [ITEMA].[ITEMA].TOTAL)) ', FORMAT_STRING = '#.#%'
select [Measures].[NUMBER] on columns,
non empty crossjoin({[ITEMA].[ITEMA].MEMBERS,[ITEMA].[ITEMA].OTHERS,[ITEMA].[ITEMA].itemmember,[ITEMA].[ITEMA].TOTAL,[ITEMA].[ITEMA].ITEMPERC},
crossjoin({ITEMB.ITEMB.children},{ITEMC.ITEMC.children,[ITEMC].[ITEMC].[others]})) on rows
FROM [MyCube]
Data Snapshot:
ITEMA_1 ITEMA_2 ........ ITEMA_itemmember ITEMA_TOTAL ITEMA_ITEMPERC
- ITEMB_1
ITEMC_1 10 20 10 100 -0.1
ITEMC_2 5 6 0 150 0.0
ITEMC_3 0 1 2 4 0.5
- ITEMB_2
ITEMC_1 ...................................................................
ITEMC_2 ...................................................................
ITEMC_3 ...................................................................
+ ITEMB_3
+ ITEMB_4
.
.
.
Hi. Thanks for the detailed query and example.
I don't see why you get a negative percentage, but I see you're using the calculated members to get values which are normally available in the cube without the use of a calculated member when you construct the right query. I think you should reconstruct your query to use the WHERE clause and re-define, and eliminate, some calculated members to get the correct results Here are my recommendations:
(1) Use the WHERE cluase to slice your qeury by the desired measure: WHERE (Measures.Number)
(2) Reference ITEMA dimension on the columns.
(3) Eliminate the following calculated members because they are not needed and we can derive the dsired values from normal intersections in the cube: (a) MEMBER [ITEMA].[ITEMA].itemmember, (b) MEMBER [ITEMA].[ITEMA].TOTAL
(4) Change the definition of MEMBER [ITEMA].[ITEMA].ITEMPERC to reference the correct cube intersections.
Assumption: ITEMA hierarchy has an "all" member, aggregation type for Measures.Number is SUM.
Here's the new query with the recommended changes:
WITH
MEMBER [ITEMA].[ITEMA].ITEMPERC AS
' Iif(IsEmpty([ITEMA].[ITEMA].[All ITEMA]),0,([ITEMA].[ITEMA].CurrentMember / [ITEMA].[ITEMA].[All ITEMA])) ', FORMAT_STRING = '0.0%'
NON EMPTY {[ITEMA].[ITEMA].MEMBERS, [ITEMA].[ITEMA].[All ITEMA], [ITEMA].[ITEMA].ITEMPERC} ON COLUMNS,
crossjoin({ITEMB.ITEMB.children},{ITEMC.ITEMC.children,[ITEMC].[ITEMC].[others]}) on rows
FROM [MyCube]
WHERE ([Measures].[NUMBER])
Hoe this helps.
PGoldy
No idea; and I guess you mean sysindexes, not sysobjects? But Books Online
says that the value should be correct since the last time the statistics
were updated (see "sysindexes"), so you might want to look at
"sp_updatestats" and "update statistics". See also p.848 of "Inside SQL
Server 2000", which mentions rowmodctr, and says that when you update
statistics, it's set to zero.
If this doesn't help, I suggest you give some more details - what version of
MSSQL, why the sysindexes value is a problem for you etc.
Simon|||I too have seen negative numbers in the sysindexes table. After reasearching I found:
There is one row in SYSINDEXES for each index and statistics set (if the table does not have a clustered index then there is a row corresponding to the heap as well), and SQL Server 2000 maintains the amount of change for indexes and statistics separately (although this was not true in SQL Server 7.0). Throughout the INSERT, UPDATE, and DELETE queries performed in a table, the rowmodctr value is increased only for the index ID 0 or 1 (there is always only one on a table). For the rest of the indexes and statistics, it shows only a relative value that has to be added to the rowmodctr of the index 0 or 1 to get the true number of changed rows for this index.
For examples and more info go to the following site, the info is near the bottom of the article :)
http://msdn.microsoft.com/library/d...l/statquery.asp
I have a cube in which the data is not being rolled up correctly when the values include negative numbers. The fact table and dimension tables are on an Oracle Server (9i). The fact table looks like:
Column Name
Data Type
Nullable
EDP_NO
NUMBER(10,0)
Yes
MONTH_YYYYMM
VARCHAR2(6 Bytes)
Yes
COGS
NUMBER
Yes
INV_VALUE
NUMBER
Yes
QTY_SOLD
NUMBER(10,0)
Yes
ITEM_NO
VARCHAR2(20 Bytes)
Yes
The dimension table looks like:
olumn Name
Data Type
Nullable
EDP_NO
NUMBER(10,0)
No
VENDOR_NAME
VARCHAR2(41 Bytes)
Yes
AP_VENDOR_NAME
VARCHAR2(41 Bytes)
Yes
DCS
VARCHAR2(4 Bytes)
Yes
DEPT_NAME
VARCHAR2(49 Bytes)
Yes
CLASS_NAME
VARCHAR2(49 Bytes)
Yes
SUB_CLASS_NAME
VARCHAR2(49 Bytes)
Yes
CATEGORY_NAME
VARCHAR2(49 Bytes)
Yes
BUYER
VARCHAR2(160 Bytes)
Yes
AP_VENDOR_NO_UI
VARCHAR2(10 Bytes)
Yes
VENDOR_NO_UI
VARCHAR2(10 Bytes)
Yes
ITEM_NAME
VARCHAR2(20 Bytes)
Yes
PLANNER
VARCHAR2(8 Bytes)
Yes
When I create the cube and browse
the data down to the most granular level (EDP_NO),and when the QTY_SOLD measure is less than
zero,SSAS reports it as being -1
larger.For example,if the value in the table is -3,then the cube browser reports it as -4.Summarized values are also off by a similar
amount.That is,if in the table the data is: -4, -3, -1,then the cube will report the total as
11.
I’m wondering if you’ve ever run
into a similar situation.I’ve verified
that the aggregation being used is SUM.
What’s weird about this is that I’m
trying to recreate a cube that already exists in SQL Server 2000.If I migrate the cube to 2005,it works correctly.It’s only when I create the cube manually
that I have this problem.
I appreciate any assistance you can offer.
Thanks,Mike Hayes
Hi Mike,
Maybe there is incorrect integer truncation, when converting from the Oracle data type: NUMBER(10,0). Since a migrated cube works correctly, could you compare the DataType for the QTY_SOLD Measure in the 2 cubes? The possible DataType values are:
http://msdn2.microsoft.com/es-es/library/ms129408.aspx
>>
SQL Server 2005 Books Online
DataType Element (ASSL)
Defines the data type of the associated element.
...
The values for DataType are defined in the System.Data.OleDb.OleDbType enumeration. However, only the enumeration values in the following table are valid in the DataType element.
BigInt
A 64-bit signed integer. This data type maps to the Int64 data type in Microsoft .NET Framework and the DBTYPE_I8 data type in OLE DB.
Bool
A Boolean value. This data type maps to the Boolean data type in the .NET Framework and the DBTYPE_BOOL data type in OLE DB.
Currency
A currency value ranging from -263 (or -922,337,203,685,477.5808) to 263-1 (or +922,337,203,685,477.5807) with an accuracy to a ten-thousandth of a currency unit. This data type maps to the Decimal data type in the .NET Framework and the DBTYPE_CY data type in OLE DB.
Date
Date data, stored as a double-precision floating point number. The whole portion is the number of days since December 30, 1899, while the fractional portion is a fraction of a day. This data type maps to the DateTime data type in the .NET Framework and the DBTYPE_DATE data type in OLE DB.
Double
A double-precision floating point number within the range of -1.79E +308 through 1.79E +308. This data type maps to the Double data type in the .NET Framework and the DBTYPE_R8 data type in OLE DB.
Integer
A 32-bit signed integer. This data type maps to the Int32 data type in the .NET Framework and the DBTYPE_I4 data type in OLE DB.
Single
A single-precision floating point number within the range of -3.40E +38 through 3.40E +38. This data type maps to the Single data type in .NET Framework and the DBTYPE_R4 data type in OLE DB.
SmallInt
A 16-bit signed integer. This data type maps to the Int16 data type in the .NET Framework and the DBTYPE_I2 data type in OLE DB.
TinyInt
An 8-bit signed integer. This data type maps to the SByte data type in the .NET Framework and the DBTYPE_I1 data type in OLE DB.
UnsignedBigInt
A 64-bit unsigned integer. This data type maps to the UInt64 data type in .NET Framework and the DBTYPE_UI8 data type in OLE DB.
UnsignedInt
A 32-bit unsigned integer. This data type maps to the UInt32 data type in the .NET Framework and the DBTYPE_UI4 data type in OLE DB.
UnsignedSmallInt
A 16-bit unsigned integer. This data type maps to the UInt16 data type in the .NET Framework and the DBTYPE_UI2 data type in OLE DB.
WChar
A null-terminated stream of Unicode characters. This data type maps to the String data type in the .NET Framework and the DBTYPE_WSTR data type in OLE DB.
Inherited
The data type of the DataItem contained in the Source element of the Measure element.
>>
|||Deepak,Thanks for the information. I think you're on the right track. The data type of the column in the migrated cube is Double, and the data type of the created cube is Int64. They should both handle the math correctly. I'm in the process of testing this. I'm trying a different data source (using oledb drivers instead of the .net drivers). If that doesn't work, I'll explicitly change the data type using a query instead of a direct link to the table.
I appreciate the info. I'll let you know what happens.
Mike
I am getting negative predictions (continuous) from a neural network model that has been trained on data that only contains positive values or zeros (no nulls).
Is there a setting that can limit the lower end of the output range to zero?
Hello
There is no algorithm setting that can limit the outputs range. However, you could use a different query construct to get this result. Assuming that your predictable column is labeled [Petal Length], your query could look like:
SELECT VBA FROM [Model] PREDICTION JOIN ...
The [IIF] function is part of a set of built-in custom functions and it is defined as
IIF( boolean_condition, true_value, false_value)
Hope this helps
Here's an example of the data.
PatientID BloodPressure Pulse Temperature Location UpdateTime
1 120/80 NULL NULL NULL 3/8/07 11:33:00
1 NULL NULL 98.5 NULL 3/8/07 11:45:30
1 NULL 82 NULL NULL 3/9/07 6:20:15
1 NULL NULL NULL RM101 3/9/07 6:24:18
1 125/85 NULL NULL NULL 3/9/07 8:15:00
2 115/75 NULL NULL NULL 3/8/07 12:32:02
2 NULL NULL 99.5 NULL 3/8/07 12:45:30
2 NULL 88 NULL NULL 3/9/07 7:20:19
2 NULL NULL NULL RM108 3/9/07 6:24:18
2 119/85 NULL NULL NULL 3/9/07 8:16:00
I need an efficient query that will return the most recent non-null value for each patientID based on the UpdateTime. Efficiency is of utmost importance because there will be hundreds of patients with potentially thousands of records.
The result set should be:
PatientID BloodPressure Pulse Temperature Location
1 125/85 82 98.5 RM101
2 119/85 88 99.5 RM108
Any help will be greatly appreciated.
If you are using SQL Server 2005, this should work although I'm not sure how well it will perform
with cte as
(select PatientID,
BloodPressure,
row_number() over(partition by PatientID
order by case when BloodPressure is null then null else UpdateTime end desc) as BloodPressureRN,
Pulse,
row_number() over(partition by PatientID
order by case when Pulse is null then null else UpdateTime end desc) as PulseRN,
Temperature,
row_number() over(partition by PatientID
order by case when Temperature is null then null else UpdateTime end desc) as TemperatureRN,
Location,
row_number() over(partition by PatientID
order by case when Location is null then null else UpdateTime end desc) as LocationRN,
UpdateTime
from mytable)
select PatientID,
max(case when BloodPressureRN=1 then BloodPressure end) as BloodPressure,
max(case when PulseRN=1 then Pulse end) as Pulse,
max(case when TemperatureRN=1 then Temperature end) as Temperature,
max(case when LocationRN=1 then Location end) as Location
from cte
group by PatientID
An alternative that works on SQL Server 2000 is:
|||declare @.basicStats table
( patientId integer not null,
bloodPressure varchar(8),
pulse smallint,
temperature numeric (4,1),
location varchar(12),
UpdateTime datetime
)insert into @.basicStats values (1, '120/80', NULL, NULL, NULL, '3/8/07 11:33:00')
insert into @.basicStats values (1, NULL, NULL, 98.5, NULL, '3/8/07 11:45:30')
insert into @.basicStats values (1, NULL, 82, NULL, NULL, '3/9/07 6:20:15')
insert into @.basicStats values (1, NULL, NULL, NULL, 'RM101', '3/9/07 6:24:18')
insert into @.basicStats values (1, '125/85', NULL, NULL, NULL, '3/9/07 8:15:00')
insert into @.basicStats values (2, '115/75', NULL, NULL, NULL, '3/8/07 12:32:02')
insert into @.basicStats values (2, NULL, NULL, 99.5, NULL, '3/8/07 12:45:30')
insert into @.basicStats values (2, NULL, 88, NULL, NULL, '3/9/07 7:20:19')
insert into @.basicStats values (2, NULL, NULL, NULL, 'RM108', '3/9/07 6:24:18')
insert into @.basicStats values (2, '119/85', NULL, NULL, NULL, '3/9/07 8:16:00')--select * from @.basicStats
select patientId,
( select top 1 BloodPressure from @.basicStats b
where b.patientId = a.patientId
and b.BloodPressure is not null
order by b.updateTime desc
) as BloodPressure,
( select top 1 pulse from @.basicStats c
where c.patientId = a.patientId
and c.pulse is not null
order by c.updateTime desc
) as pulse,
( select top 1 temperature from @.basicStats d
where d.patientId = a.patientId
and d.temperature is not null
order by d.updateTime desc
) as temperature,
( select top 1 location from @.basicStats e
where e.patientId = a.patientId
and e.location is not null
order by e.updateTime desc
) as location
from @.basicStats a
group by patientId-- patientId BloodPressure pulse temperature location
-- -- - --
-- 1 125/85 82 98.5 RM101
-- 2 119/85 88 99.5 RM108
And a third solution (sorry Kent, I pinched your table declaration and inserts for this one)...
This solution appears to be more expensive than Kent's solution, according to the execution plan on my machine. You'll probably experience the same, or you might not - it's just another option for you to try out on your hardware.
Chris
declare @.basicStats table
(
patientId integer not null,
bloodPressure varchar(8),
pulse smallint,
temperature numeric (4,1),
location varchar(12),
UpdateTime datetime
)
insert into @.basicStats values (1, '120/80', NULL, NULL, NULL, '3/8/07 11:33:00')
insert into @.basicStats values (1, NULL, NULL, 98.5, NULL, '3/8/07 11:45:30')
insert into @.basicStats values (1, NULL, 82, NULL, NULL, '3/9/07 6:20:15')
insert into @.basicStats values (1, NULL, NULL, NULL, 'RM101', '3/9/07 6:24:18')
insert into @.basicStats values (1, '125/85', NULL, NULL, NULL, '3/9/07 8:15:00')
insert into @.basicStats values (2, '115/75', NULL, NULL, NULL, '3/8/07 12:32:02')
insert into @.basicStats values (2, NULL, NULL, 99.5, NULL, '3/8/07 12:45:30')
insert into @.basicStats values (2, NULL, 88, NULL, NULL, '3/9/07 7:20:19')
insert into @.basicStats values (2, NULL, NULL, NULL, 'RM108', '3/9/07 6:24:18')
insert into @.basicStats values (2, '119/85', NULL, NULL, NULL, '3/9/07 8:16:00')
SELECT DISTINCT
p.PatientID,
pbp.BloodPressure,
ppu.Pulse,
pt.Temperature,
pl.Location
FROM @.basicStats p
|||INNER JOIN (SELECT PatientID, MAX(UpdateTime) AS UpdateTime FROM @.basicStats WHERE BloodPressure IS NOT NULL GROUP BY PatientID) bp ON bp.PatientID = p.PatientID
INNER JOIN @.basicStats pbp ON pbp.PatientID = bp.PatientID AND pbp.UpdateTime = bp.UpdateTime
INNER JOIN (SELECT PatientID, MAX(UpdateTime) AS UpdateTime FROM @.basicStats WHERE Pulse IS NOT NULL GROUP BY PatientID) pu ON pu.PatientID = p.PatientID
INNER JOIN @.basicStats ppu ON ppu.PatientID = bp.PatientID AND ppu.UpdateTime = pu.UpdateTime
INNER JOIN (SELECT PatientID, MAX(UpdateTime) AS UpdateTime FROM @.basicStats WHERE Temperature IS NOT NULL GROUP BY PatientID) t ON t.PatientID = p.PatientID
INNER JOIN @.basicStats pt ON pt.PatientID = bp.PatientID AND pt.UpdateTime = t.UpdateTime
INNER JOIN (SELECT PatientID, MAX(UpdateTime) AS UpdateTime FROM @.basicStats WHERE Location IS NOT NULL GROUP BY PatientID) l ON l.PatientID = p.PatientID
INNER JOIN @.basicStats pl ON pl.PatientID = bp.PatientID AND pl.UpdateTime = l.UpdateTime
Gary:
Please forgive me, but this is a kind of query that I have struggled with. Since you are interested in optimum performance I think it woul be best if you could get Umachandar or someone similar to comment. I am just too afraid that I will get this wrong.
|||
Kent
Mark's solution will work fine except that you will end up sorting the entire table 4 times (once each to compute row number for bloodpressure, pulse, temperature and location). If you have a large table this will be problematic. The other solutions also suffer from the same problem. SQL Server unfortunately doesn't have a concept of filtered indexes which will help in this case. Database systems like PostgreSQL can do better job because you can create filtered index (on non-null value of each attribute you are interested). Similarly, in Oracle you can make use of index compression to reduce I/O costs due to repeated values (NULL) or use function-based indexes. DB2 also has some features that you can take advantage of for this type of schema.
In SQL Server you can use indexed views to achieve the filtered indexes functionality. So define one indexed view per property like:
create view basicStats_bloodPressure
with schemabinding
as
select patientId, bloodPressure, UpdateTime
from dbo.basicStats
where bloodPressure is not null
go
create unique clustered index idx_basicStats_bloodPressure on basicStats_bloodPressure(patientId, UpdateTime desc)
go
create view basicStats_pulse
with schemabinding
as
select patientId, pulse, UpdateTime
from dbo.basicStats
where pulse is not null
go
create unique clustered index idx_basicStats_pulse on basicStats_pulse(patientId, UpdateTime desc)
go
create view basicStats_temperature
with schemabinding
as
select patientId, temperature, UpdateTime
from dbo.basicStats
where temperature is not null
go
create unique clustered index idx_basicStats_temperature on basicStats_temperature(patientId, UpdateTime desc)
go
create view basicStats_location
with schemabinding
as
select patientId, location, UpdateTime
from dbo.basicStats
where location is not null
go
create unique clustered index idx_basicStats_location on basicStats_location(patientId, UpdateTime desc)
go
And create an index on the table too like:
create clustered index idx_basicstats_patientid on basicStats( patientId )
Now, your query is as simple as what Kent had and SQL Server will automatically use the indexed views.
select patientId,
( select top 1 BloodPressure from basicStats b
where b.patientId = a.patientId
and b.BloodPressure is not null
order by b.updateTime desc
) as BloodPressure,
( select top 1 pulse from basicStats c
where c.patientId = a.patientId
and c.pulse is not null
order by c.updateTime desc
) as pulse,
( select top 1 temperature from basicStats d
where d.patientId = a.patientId
and d.temperature is not null
order by d.updateTime desc
) as temperature,
( select top 1 location from basicStats e
where e.patientId = a.patientId
and e.location is not null
order by e.updateTime desc
) as location
from basicStats a
group by patientId;
-- or below referencing indexed views directly
select patientId
, (select top 1 t1.bloodPressure from basicStats_bloodPressure as t1 where t1.patientId = b.patientId order by t1.UpdateTime desc) as bloodPressure
, (select top 1 t1.pulse from basicStats_pulse as t1 where t1.patientId = b.patientId order by t1.UpdateTime desc) as pulse
, (select top 1 t1.temperature from basicStats_temperature as t1 where t1.patientId = b.patientId order by t1.UpdateTime desc) as temperature
, (select top 1 t1.location from basicStats_location as t1 where t1.patientId = b.patientId order by t1.UpdateTime desc) as location
from (
select distinct patientId
from basicStats
) as b
These indexed views will need to be maintained during DML operations. But this is probably the best way to get the performance for this query given the nature of your data. You do incur some additional storage costs.
Alternatively, you should simply partition the table by property and use my last query except each indexed view is a physical table and the main table only contains the patientId columns & others that are not partitioned:
select patientId
, (select top 1 t1.bloodPressure from basicStats_bloodPressure as t1 where t1.patientId = b.patientId order by t1.UpdateTime desc) as bloodPressure
, (select top 1 t1.pulse from basicStats_pulse as t1 where t1.patientId = b.patientId order by t1.UpdateTime desc) as pulse
, (select top 1 t1.temperature from basicStats_temperature as t1 where t1.patientId = b.patientId order by t1.UpdateTime desc) as temperature
, (select top 1 t1.location from basicStats_location as t1 where t1.patientId = b.patientId order by t1.UpdateTime desc) as location
from (
select distinct patientId
from basicStats
) as b
With this approach, you will save some storage also. DML operations are slightly complex and you need to do additional work instead of SQL Server with the indexed views approach. For example, if you insert any row then you need to first check if there is a row in the main table for that patientId first and then insert into the separate property table. This might work out better than the indexed views approach also. So test both and see. Indexed views approach however is straight forward and doesn't require much changes to your existing code.
|||( I knew it would be worth it; thanks, Umachandar. WOA! )|||Wow thanks guys for the advice. I'll try some of these and give some feedback.Thanks again!
Gary B.
Hello, I have worked with SQL Server 2000 but now we have a requirement where I need to write values from an asp.net form into an XML type in SQL Server 2005.
I have never used XML as a type in SQL Server 2005. How do we write xml into xml type.
For example the structure of XML is something like:
<application>
<applicationID = "value"></applicationID>
<customerName="value></customerName>
</application>
I have to write this kind of XML into the XML type and later retrieve these XML values and populate the form again.
Kindly suggest. Thanks a lot.
You will need to look into several things to help you achieve this.
Look into the System.Xml.XmlTextWriter to help you construct XML valid strings
Also look into System.IO.StreamWriter to write the stream of data
You can then use methods of the XmlTextWriter to write the elements, attributes based on your XML structure; WriteStartDocument(), WriteStartElement(), WriteElementString();
Hi,
I have written a stored procedure to store values from a report i generated to the DB. Now there is a column PKID which is the primary key but also needs to be repeated at times. I tried to clear the memory that the same PKID has already been entered for which I wrote another SP.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spCRMPublisherSummaryUpdate](
@.ReportDate smalldatetime,
@.SiteID int,
@.DataFeedID int,
@.FromCode varchar,
@.Sent int,
@.Delivered int,
@.TotalOpens REAL,
@.UniqueUserOpens REAL,
@.UniqueUserMessageClicks REAL,
@.Unsubscribes REAL,
@.Bounces REAL,
@.UniqueUserLinkClicks REAL,
@.TotalLinkClicks REAL,
@.SpamComplaints int,
@.Cost int
)
AS
SET NOCOUNT ON
DECLARE @.PKID INT
DECLARE @.TagID INT
SELECT @.TagID=ID FROM Tag WHERE SiteID=@.SiteID AND FromCode=@.FromCode
SELECT @.PKID=PKID FROM DimTag
WHERE TagID=@.TagID AND StartDate<=@.ReportDate AND @.ReportDate< ISNULL(EndDate,'12/31/2050')
IF @.PKID IS NULL BEGIN
SELECT TOP 1 @.PKID=PKID FROM DimTag WHERE TagID=@.TagID AND SiteID=@.SiteID
DECLARE @.LastReportDate smalldatetime, @.LastSent INT, @.LastDelivered INT, @.LastTotalOpens Real,
@.LastUniqueUserOpens Real, @.LastUniqueUserMessageClicks Real, @.LastUniqueUserLinkClicks Real,
@.LastTotalLinkClicks Real, @.LastUnsubscribes Real, @.LastBounces Real, @.LastSpamComplaints INT, @.LastCost INT
SELECT @.Sent=@.Sent-Sent,@.Delivered=@.Delivered-Delivered,@.TotalOpens=@.TotalOpens-TotalOpens,
@.UniqueUserOpens=@.UniqueUserOpens-UniqueUserOpens,@.UniqueUserMessageClicks=@.UniqueUserMessageClicks-UniqueUserMessageClicks,
@.UniqueUserLinkClicks=@.UniqueUserLinkClicks-UniqueUserLinkClicks,@.TotalLinkClicks=@.TotalLinkClicks-TotalLinkClicks,
@.Unsubscribes=@.Unsubscribes-Unsubscribes,@.Bounces=@.Bounces-Bounces,@.SpamComplaints=@.SpamComplaints-SpamComplaints,
@.Cost=@.Cost-Cost
FROM CrmPublisherSummary
WHERE @.LastReportDate < @.ReportDate
AND SiteID=@.SiteID
AND TagPKID=@.PKID
UPDATE CrmPublisherSummary SET
Sent=@.Sent,
Delivered=@.Delivered,
TotalOpens=@.TotalOpens,
UniqueUserOpens=@.UniqueUserOpens,
UniqueUserMessageClicks=@.UniqueUserMessageClicks,
UniqueUserLinkClicks=@.UniqueUserLinkClicks,
TotalLinkClicks=@.TotalLinkClicks,
Unsubscribes=@.Unsubscribes,
Bounces=@.Bounces,
SpamComplaints=@.SpamComplaints,
Cost=@.Cost,
TagID=@.TagID
WHERE ReportDate=@.ReportDate
AND SiteID=@.SiteID
AND TagPKID=@.PKID
END
ELSE
INSERT INTO CrmPublisherSummary(
ReportDate, SiteID, TagPKID, Sent, Delivered, TotalOpens, UniqueUserOpens,
UniqueUserMessageClicks, UniqueUserLinkClicks, TotalLinkClicks, Unsubscribes,
Bounces, SpamComplaints, Cost, DataFeedID, TagID)
VALUES(
@.ReportDate, @.SiteID, @.PKID, @.Sent, @.Delivered, @.TotalOpens, @.UniqueUserOpens,
@.UniqueUserMessageClicks, @.UniqueUserLinkClicks, @.TotalLinkClicks, @.Unsubscribes,
@.Bounces, @.SpamComplaints, @.Cost, @.DataFeedID, @.TagID)
SET NOCOUNT OFF
this is the one to clear:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[spCRMPublisherSummaryClear](
@.SiteID INT,
@.DataFeedID INT,
@.ReportDate SMALLDATETIME) AS
DELETE LandingSiteSummary
WHERE SiteID=@.SiteID AND ReportDate=@.ReportDate
but it doesnt seem to be working.
Please suggest.
avidyarthi:
I have written a stored procedure to store values from a report i generated to the DB. Now there is a column PKID which is the primary key but also needs to be repeated at times.
you cannot repeat a value in a column that is set as your primary key. If you need to repeat values in that column, then you need to remove its designation as your primary key.
|||
hey,
thanks i worked my way around it.