Seal Report Forum
»
General
»
General Discussions/Other
»
How to pass one restriction value to another
Rank: Newbie
Groups: Registered
Joined: 1/29/2016(UTC) Posts: 8 Location: Mumbai Thanks: 1 times
|
I have a report which uses query and master table to get data from database. I need to have to restrictions date between and less than date as main query contains union and need between date for some union and less than in some.. how I can take first date of between restriction and pass as lower than date as it will be treated as opening date. I wanted to achieve this as user will enter only 1 restriction will this work if added in Preload script of Model Code:model.GetRestrictionByName("Ldt").Value1 = model.GetRestrictionByName("Dt").Value1;
Regards Arvind
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 12/20/2013(UTC) Posts: 1,209 Thanks: 14 times Was thanked: 206 time(s) in 199 post(s)
|
Yes, but for a date it is Code:model.GetRestrictionByName("Ldt").Date1 = model.GetRestrictionByName("Dt").Date1;
you can use Date1,Date2,Date3,Date4 for a numeric or string it is Value1,Value2,Value3,Value4 For a enumerated list it is a List<string> called EnumValues Code:model.GetRestrictionByName("Ldt").EnumValues = model.GetRestrictionByName("Dt").EnumValues;
Edited by user Wednesday, March 28, 2018 8:38:09 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 1/29/2016(UTC) Posts: 8 Location: Mumbai Thanks: 1 times
|
Thanks it works, but how add restrictions for inner select query of union. Edit: Will try this and update https://sealreport.org/f...=posts&t=278#post630above solutions seems working only thing is my restriction is Date Code:table.Sql = ((string)model.Report.Tag).Replace("31-Dec-2017",model.GetRestrictionByName("Dt").Date1);
it returns error datetime can not convert to string. I tried with Tostring() at the end of restriction but it does not work. Change 'Tostring()' to 'ToString()' works Edited by user Wednesday, March 21, 2018 4:37:32 PM(UTC)
| Reason: Got answer in another post
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 1/29/2016(UTC) Posts: 8 Location: Mumbai Thanks: 1 times
|
Code:table.Sql = ((string)model.Report.Tag).Replace("31-Dec-2017",model.GetRestrictionByName("Dt").Date1.ToString());
returns '31/12/2017 12:00:00 AM' whereas we need to format it to only Date "31-Dec-2017". how to achieve this?? Error detail: The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value. Edited by user Wednesday, March 21, 2018 5:00:29 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 1/29/2016(UTC) Posts: 8 Location: Mumbai Thanks: 1 times
|
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 12/20/2013(UTC) Posts: 1,209 Thanks: 14 times Was thanked: 206 time(s) in 199 post(s)
|
Yes well done, another clever approach could be to modify the JOIN Clause of the joins used by the engine... You have to select the Join used from the Source of the Model, then you can modify the Join Clause it for your purpose. I made a quick try on SQL Server with a restriction named 'Date' and a Join having name starting with 'Purchase': Code: var join = model.Source.MetaData.Joins.FirstOrDefault(i => i.Name.StartsWith("Purchase"));
if (model.Tag == null) { //Save the orginal clause in the Tag
model.Tag = join.Clause;
}
join.Clause = ((string)model.Tag) + string.Format(" AND getdate() > '{0:yyyy-MM-dd HH:mm:ss}'", model.GetRestrictionByName("Date").Date1);
log.LogMessage("New Clause: " + join.Clause);
Edited by user Thursday, March 22, 2018 10:07:00 AM(UTC)
| Reason: Not specified
|
1 user thanked epf for this useful post.
|
|
|
Rank: Newbie
Groups: Registered
Joined: 1/29/2016(UTC) Posts: 8 Location: Mumbai Thanks: 1 times
|
Originally Posted by: epf Yes well done, another clever approach could be to modify the JOIN Clause of the joins used by the engine... You have to select the Join used from the Source of the Model, then you can modify the Join Clause it for your purpose. I made a quick try on SQL Server with a restriction named 'Date' and a Join having name starting with 'Purchase': Code: var join = model.Source.MetaData.Joins.FirstOrDefault(i => i.Name.StartsWith("Purchase"));
if (model.Tag == null) { //Save the orginal clause in the Tag
model.Tag = join.Clause;
}
join.Clause = ((string)model.Tag) + string.Format(" AND getdate() > '{0:yyyy-MM-dd HH:mm:ss}'", model.GetRestrictionByName("Date").Date1);
log.LogMessage("New Clause: " + join.Clause);
Thank you for your support. I will try this with my next report as I have to make several reports with this tool. Thanks again..
|
|
|
|
Seal Report Forum
»
General
»
General Discussions/Other
»
How to pass one restriction value to another
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.