Hello everyone, Is it posssible when I click the field in main subreport, it will show the subreport... I have five field and five subreport.
Pls. help...
Thanks!!!I suggest to add 5 sections and in each put your subreport.
then in your app you could suppress section and show subreport that you want.
Showing posts with label field. Show all posts
Showing posts with label field. Show all posts
Wednesday, March 28, 2012
Monday, March 19, 2012
Line Break down
I have a forumla {@.frmPrevMonth} and it contains information like... "21,36.02,11141.75,1" which it came from a Parameter field.
It can contain more of less information.
What I need is that it can be broke down in order in which they came.
1st Detail line: 21
2nd Detail line: 36.02
3rd Detail line: 11141.75
4th Detail line: 1
How can I achive this?You are going to use the left(), Mid(), and right() functions.
You will have 4 formulas.
This will work for the number you show.
1. Left({@.frmPrevMonth} ,2) // gets 21
2. Mid({@.frmPrevMonth} ,4,5) // gets 36.02
3. Mid({@.frmPrevMonth} 10,8) // gets 11141.75
4. Right({@.frmPrevMonth} ,1) // gets 1
GJ|||I forgot to put down that the numbers vary in size and it is not always 4 things I need. It can be a total of 10 lines or 1 line.|||Ok here is a formula that will get the first strings before the first comma.
I assume you want the values between the commas.
'This formula uses Basic syntax
dim StringInput as string
dim Character as string
dim NumberOfCharacters as number
'The StringInput, Character and NumberOfCharacters
'variables can be changed to your values
StringInput = {@.Number}
Character = ","
NumberOfCharacters = 0
'NumberOfCharacters specifies that the token returned
'If the token to be retrieved comes before the first
'occurrence of Character, use 0 for NumberOfCharacters.
dim Token as number
dim Increment as number
dim Output as string
dim Ender as number
Ender = NumberOfCharacters + 1
do until Token = Ender or Increment = length(StringInput)
Increment = Increment + 1
if StringInput(Increment) = Character then Token= Token + 1
if Ender - Token = 1 and StringInput(Increment) <> Character then Output = Output + StringInput(Increment)
loop
Formula = Output
If you could have up to 10 lines then you will have 10 formulas the way I show, just change the variable at NumberOfCharacters. 1st formula has a 0, 2nd would have a 1 and up to 9 for 10 lines.
Hope that makes sense, someone else might have an easier way of doing this.
GJ|||Look at the help for the Split function, and on arrays.
e.g.
stringvar array parts := split({table.field}); //or maybe numbervar, if all your parts are numbers
parts[2] //return the 2nd part|||Oops, meant to add the 2nd parameter to the split function:
split({table.field}, ',');|||I tried the split function.
Attached is what I am looking for. Thanks.|||Ok here is a formula that will get the first strings before the first comma.
I assume you want the values between the commas.
'This formula uses Basic syntax
dim StringInput as string
dim Character as string
dim NumberOfCharacters as number
'The StringInput, Character and NumberOfCharacters
'variables can be changed to your values
StringInput = {@.Number}
Character = ","
NumberOfCharacters = 0
'NumberOfCharacters specifies that the token returned
'If the token to be retrieved comes before the first
'occurrence of Character, use 0 for NumberOfCharacters.
dim Token as number
dim Increment as number
dim Output as string
dim Ender as number
Ender = NumberOfCharacters + 1
do until Token = Ender or Increment = length(StringInput)
Increment = Increment + 1
if StringInput(Increment) = Character then Token= Token + 1
if Ender - Token = 1 and StringInput(Increment) <> Character then Output = Output + StringInput(Increment)
loop
Formula = Output
If you could have up to 10 lines then you will have 10 formulas the way I show, just change the variable at NumberOfCharacters. 1st formula has a 0, 2nd would have a 1 and up to 9 for 10 lines.
Hope that makes sense, someone else might have an easier way of doing this.
GJ
ok. how can I dynamically increase the "NumberOfCharacters" after everytime a record is read and then have it display it on the detail line?|||Have not had time today to work formula. Why not use the split function like JaganEllis suggested. It's quicker and easier to understand.
GJ|||An example to produce what I think you want:
local stringvar a := "21,36.02,11141.75,1";
local stringvar array parts := split(a, ',');
local numbervar i;
local stringvar out;
for i := 1 to ubound(parts) do
(
out := out + parts[i] + chr(13) + chr(10);
);
out
And remember to check the 'Can Grow' option for the field, in the Common tab of the Format Field option.
It can contain more of less information.
What I need is that it can be broke down in order in which they came.
1st Detail line: 21
2nd Detail line: 36.02
3rd Detail line: 11141.75
4th Detail line: 1
How can I achive this?You are going to use the left(), Mid(), and right() functions.
You will have 4 formulas.
This will work for the number you show.
1. Left({@.frmPrevMonth} ,2) // gets 21
2. Mid({@.frmPrevMonth} ,4,5) // gets 36.02
3. Mid({@.frmPrevMonth} 10,8) // gets 11141.75
4. Right({@.frmPrevMonth} ,1) // gets 1
GJ|||I forgot to put down that the numbers vary in size and it is not always 4 things I need. It can be a total of 10 lines or 1 line.|||Ok here is a formula that will get the first strings before the first comma.
I assume you want the values between the commas.
'This formula uses Basic syntax
dim StringInput as string
dim Character as string
dim NumberOfCharacters as number
'The StringInput, Character and NumberOfCharacters
'variables can be changed to your values
StringInput = {@.Number}
Character = ","
NumberOfCharacters = 0
'NumberOfCharacters specifies that the token returned
'If the token to be retrieved comes before the first
'occurrence of Character, use 0 for NumberOfCharacters.
dim Token as number
dim Increment as number
dim Output as string
dim Ender as number
Ender = NumberOfCharacters + 1
do until Token = Ender or Increment = length(StringInput)
Increment = Increment + 1
if StringInput(Increment) = Character then Token= Token + 1
if Ender - Token = 1 and StringInput(Increment) <> Character then Output = Output + StringInput(Increment)
loop
Formula = Output
If you could have up to 10 lines then you will have 10 formulas the way I show, just change the variable at NumberOfCharacters. 1st formula has a 0, 2nd would have a 1 and up to 9 for 10 lines.
Hope that makes sense, someone else might have an easier way of doing this.
GJ|||Look at the help for the Split function, and on arrays.
e.g.
stringvar array parts := split({table.field}); //or maybe numbervar, if all your parts are numbers
parts[2] //return the 2nd part|||Oops, meant to add the 2nd parameter to the split function:
split({table.field}, ',');|||I tried the split function.
Attached is what I am looking for. Thanks.|||Ok here is a formula that will get the first strings before the first comma.
I assume you want the values between the commas.
'This formula uses Basic syntax
dim StringInput as string
dim Character as string
dim NumberOfCharacters as number
'The StringInput, Character and NumberOfCharacters
'variables can be changed to your values
StringInput = {@.Number}
Character = ","
NumberOfCharacters = 0
'NumberOfCharacters specifies that the token returned
'If the token to be retrieved comes before the first
'occurrence of Character, use 0 for NumberOfCharacters.
dim Token as number
dim Increment as number
dim Output as string
dim Ender as number
Ender = NumberOfCharacters + 1
do until Token = Ender or Increment = length(StringInput)
Increment = Increment + 1
if StringInput(Increment) = Character then Token= Token + 1
if Ender - Token = 1 and StringInput(Increment) <> Character then Output = Output + StringInput(Increment)
loop
Formula = Output
If you could have up to 10 lines then you will have 10 formulas the way I show, just change the variable at NumberOfCharacters. 1st formula has a 0, 2nd would have a 1 and up to 9 for 10 lines.
Hope that makes sense, someone else might have an easier way of doing this.
GJ
ok. how can I dynamically increase the "NumberOfCharacters" after everytime a record is read and then have it display it on the detail line?|||Have not had time today to work formula. Why not use the split function like JaganEllis suggested. It's quicker and easier to understand.
GJ|||An example to produce what I think you want:
local stringvar a := "21,36.02,11141.75,1";
local stringvar array parts := split(a, ',');
local numbervar i;
local stringvar out;
for i := 1 to ubound(parts) do
(
out := out + parts[i] + chr(13) + chr(10);
);
out
And remember to check the 'Can Grow' option for the field, in the Common tab of the Format Field option.
Monday, March 12, 2012
Limiting traces in Profiler
I've opened a trace in Profile, and now want to limit the results based on
the TextData field. I've setup a filter for "textdata not like exec
some_existing_sp" and that worked fine.
How is a "or" added here, if possible?
I'd like a filter something like "textdata not like (exec some_existing_sp)
or (exec some_existing_sp2)".
Or and "()" don't seem to work though.
Marco
Close and expand the 'NOT LIKE' and you should get another input box.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Marco Shaw" <marco@.Znbnet.nb.ca> wrote in message
news:uQLNEDl4GHA.1248@.TK2MSFTNGP03.phx.gbl...
> I've opened a trace in Profile, and now want to limit the results based on
> the TextData field. I've setup a filter for "textdata not like exec
> some_existing_sp" and that worked fine.
> How is a "or" added here, if possible?
> I'd like a filter something like "textdata not like (exec
> some_existing_sp)
> or (exec some_existing_sp2)".
> Or and "()" don't seem to work though.
> Marco
>
the TextData field. I've setup a filter for "textdata not like exec
some_existing_sp" and that worked fine.
How is a "or" added here, if possible?
I'd like a filter something like "textdata not like (exec some_existing_sp)
or (exec some_existing_sp2)".
Or and "()" don't seem to work though.
Marco
Close and expand the 'NOT LIKE' and you should get another input box.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Marco Shaw" <marco@.Znbnet.nb.ca> wrote in message
news:uQLNEDl4GHA.1248@.TK2MSFTNGP03.phx.gbl...
> I've opened a trace in Profile, and now want to limit the results based on
> the TextData field. I've setup a filter for "textdata not like exec
> some_existing_sp" and that worked fine.
> How is a "or" added here, if possible?
> I'd like a filter something like "textdata not like (exec
> some_existing_sp)
> or (exec some_existing_sp2)".
> Or and "()" don't seem to work though.
> Marco
>
Limiting traces in Profiler
I've opened a trace in Profile, and now want to limit the results based on
the TextData field. I've setup a filter for "textdata not like exec
some_existing_sp" and that worked fine.
How is a "or" added here, if possible?
I'd like a filter something like "textdata not like (exec some_existing_sp)
or (exec some_existing_sp2)".
Or and "()" don't seem to work though.
MarcoClose and expand the 'NOT LIKE' and you should get another input box.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Marco Shaw" <marco@.Znbnet.nb.ca> wrote in message
news:uQLNEDl4GHA.1248@.TK2MSFTNGP03.phx.gbl...
> I've opened a trace in Profile, and now want to limit the results based on
> the TextData field. I've setup a filter for "textdata not like exec
> some_existing_sp" and that worked fine.
> How is a "or" added here, if possible?
> I'd like a filter something like "textdata not like (exec
> some_existing_sp)
> or (exec some_existing_sp2)".
> Or and "()" don't seem to work though.
> Marco
>
the TextData field. I've setup a filter for "textdata not like exec
some_existing_sp" and that worked fine.
How is a "or" added here, if possible?
I'd like a filter something like "textdata not like (exec some_existing_sp)
or (exec some_existing_sp2)".
Or and "()" don't seem to work though.
MarcoClose and expand the 'NOT LIKE' and you should get another input box.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Marco Shaw" <marco@.Znbnet.nb.ca> wrote in message
news:uQLNEDl4GHA.1248@.TK2MSFTNGP03.phx.gbl...
> I've opened a trace in Profile, and now want to limit the results based on
> the TextData field. I've setup a filter for "textdata not like exec
> some_existing_sp" and that worked fine.
> How is a "or" added here, if possible?
> I'd like a filter something like "textdata not like (exec
> some_existing_sp)
> or (exec some_existing_sp2)".
> Or and "()" don't seem to work though.
> Marco
>
Limiting traces in Profiler
I've opened a trace in Profile, and now want to limit the results based on
the TextData field. I've setup a filter for "textdata not like exec
some_existing_sp" and that worked fine.
How is a "or" added here, if possible?
I'd like a filter something like "textdata not like (exec some_existing_sp)
or (exec some_existing_sp2)".
Or and "()" don't seem to work though.
MarcoClose and expand the 'NOT LIKE' and you should get another input box.
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Marco Shaw" <marco@.Znbnet.nb.ca> wrote in message
news:uQLNEDl4GHA.1248@.TK2MSFTNGP03.phx.gbl...
> I've opened a trace in Profile, and now want to limit the results based on
> the TextData field. I've setup a filter for "textdata not like exec
> some_existing_sp" and that worked fine.
> How is a "or" added here, if possible?
> I'd like a filter something like "textdata not like (exec
> some_existing_sp)
> or (exec some_existing_sp2)".
> Or and "()" don't seem to work though.
> Marco
>
the TextData field. I've setup a filter for "textdata not like exec
some_existing_sp" and that worked fine.
How is a "or" added here, if possible?
I'd like a filter something like "textdata not like (exec some_existing_sp)
or (exec some_existing_sp2)".
Or and "()" don't seem to work though.
MarcoClose and expand the 'NOT LIKE' and you should get another input box.
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Marco Shaw" <marco@.Znbnet.nb.ca> wrote in message
news:uQLNEDl4GHA.1248@.TK2MSFTNGP03.phx.gbl...
> I've opened a trace in Profile, and now want to limit the results based on
> the TextData field. I've setup a filter for "textdata not like exec
> some_existing_sp" and that worked fine.
> How is a "or" added here, if possible?
> I'd like a filter something like "textdata not like (exec
> some_existing_sp)
> or (exec some_existing_sp2)".
> Or and "()" don't seem to work though.
> Marco
>
Friday, March 9, 2012
Limiting Amount of Text in a box
I have Comments field in my db that can contain many lines of text and when
it displays in the report the textbox grow extensively. How can I limit the
amount that the text box grows, OR limit the amount of text that is
retrieved in my query, i.e., I only want to display 10-15 lines out of
potentially 80-100.
Thanks
DeanYou can try to show only the first N characters doing it in your SQL
sentence or in the Cell Expresion:
IN SQL:
SELECT substring(YourtextField, 1, N) as Comments, ... FROM YourTable
IN Your cell expresion:
= Mid(Fields!YourField.Value, 1, N)
Does it help?
"Dean" <deanl144@.hotmail.com.nospam> escribió en el mensaje
news:%23M8giJhIIHA.5764@.TK2MSFTNGP06.phx.gbl...
>I have Comments field in my db that can contain many lines of text and when
>it displays in the report the textbox grow extensively. How can I limit the
>amount that the text box grows, OR limit the amount of text that is
>retrieved in my query, i.e., I only want to display 10-15 lines out of
>potentially 80-100.
> Thanks
> Dean
>|||On Nov 8, 9:19 am, "Dean" <deanl...@.hotmail.com.nospam> wrote:
> I have Comments field in my db that can contain many lines of text and when
> it displays in the report the textbox grow extensively. How can I limit the
> amount that the text box grows, OR limit the amount of text that is
> retrieved in my query, i.e., I only want to display 10-15 lines out of
> potentially 80-100.
> Thanks
> Dean
You could create a custom code that counts the carriage return
characters (vbCr, vbLf, vbCrLf depending on your encoding), and if
there are more than 10 in your input string, truncate it using the
Left function
Off the top of my head, it would look something like this:
Function TextTrimmer( txt As String ) As String
lineCount = 0
returnOffset = 1
While lineCount < 10 and returnOffset > 0
returnOffset = InStr( returnOffset+1, txt, vbCr)
lineCount = lineCount + 1
Wend
If returnOffset = 0 Then
' ran out of characters in the string before reaching 10 lines
return( txt )
Else
return( Left( txt, returnOffset-1 ) & "..." )
End If
End Function
Then in the textbox, use
=Code.TextTrimmer( Fields!ReallyLongText.Value )
-- Scott
it displays in the report the textbox grow extensively. How can I limit the
amount that the text box grows, OR limit the amount of text that is
retrieved in my query, i.e., I only want to display 10-15 lines out of
potentially 80-100.
Thanks
DeanYou can try to show only the first N characters doing it in your SQL
sentence or in the Cell Expresion:
IN SQL:
SELECT substring(YourtextField, 1, N) as Comments, ... FROM YourTable
IN Your cell expresion:
= Mid(Fields!YourField.Value, 1, N)
Does it help?
"Dean" <deanl144@.hotmail.com.nospam> escribió en el mensaje
news:%23M8giJhIIHA.5764@.TK2MSFTNGP06.phx.gbl...
>I have Comments field in my db that can contain many lines of text and when
>it displays in the report the textbox grow extensively. How can I limit the
>amount that the text box grows, OR limit the amount of text that is
>retrieved in my query, i.e., I only want to display 10-15 lines out of
>potentially 80-100.
> Thanks
> Dean
>|||On Nov 8, 9:19 am, "Dean" <deanl...@.hotmail.com.nospam> wrote:
> I have Comments field in my db that can contain many lines of text and when
> it displays in the report the textbox grow extensively. How can I limit the
> amount that the text box grows, OR limit the amount of text that is
> retrieved in my query, i.e., I only want to display 10-15 lines out of
> potentially 80-100.
> Thanks
> Dean
You could create a custom code that counts the carriage return
characters (vbCr, vbLf, vbCrLf depending on your encoding), and if
there are more than 10 in your input string, truncate it using the
Left function
Off the top of my head, it would look something like this:
Function TextTrimmer( txt As String ) As String
lineCount = 0
returnOffset = 1
While lineCount < 10 and returnOffset > 0
returnOffset = InStr( returnOffset+1, txt, vbCr)
lineCount = lineCount + 1
Wend
If returnOffset = 0 Then
' ran out of characters in the string before reaching 10 lines
return( txt )
Else
return( Left( txt, returnOffset-1 ) & "..." )
End If
End Function
Then in the textbox, use
=Code.TextTrimmer( Fields!ReallyLongText.Value )
-- Scott
Friday, February 24, 2012
Limit to one value in fld b for given value in field a
Okay, i have a problem, which would be easy in a well-normalized db,
but im working in a legacy app here, and can't normalize the db because
it would break the existing apps around it.
I have a manifest table which essentially acts as both a header & line-items
table.
There is a MANIFESTID field which serves to link the lineitems together onto
one
manifest. There is also an ACTION field, which serves to indicate whether
the
manifest is for delivery or for pickup.
I dont know if it really is this hard, or if im just brain-freezing here,
but here is what
i'm trying to do... i want to put in some sort of constraint so that for all
the lines which
have any given MANIFESTID, the ACTION field is the same on all of them.
Thanks in advance,
- Arthur Dent.Not sure if I fully understood your problem, but in SQL Server, you cannot
create a constraint declaratively which can enforce some logic based on
multiple rows.
A general alternative is to use a after trigger with a rollback statement.
This is somewhat prohibitive in high performance systems since the logic can
turn out to be complex depending on your schema. In rare cases, you might be
able to work it out with a scalar udf used in a check constraint as well.
Anith|||As example for clarification,
ACTION is declared with a check as either D or P or Delivery or Pickup.
I might have 5 rows where the ManifestID is <10>. What i want is to be able
to say
For All Rows Where MANIFESTID = 10,
ACTION on ALL 5 Rows can be 'D' or 'P', but they ALL
must be 'D' or ALL must be 'P'
"Anith Sen" <anith@.bizdatasolutions.com> wrote in message
news:%23Y4JaqG7FHA.3544@.TK2MSFTNGP09.phx.gbl...
> Not sure if I fully understood your problem, but in SQL Server, you cannot
> create a constraint declaratively which can enforce some logic based on
> multiple rows.
> A general alternative is to use a after trigger with a rollback statement.
> This is somewhat prohibitive in high performance systems since the logic
> can turn out to be complex depending on your schema. In rare cases, you
> might be able to work it out with a scalar udf used in a check constraint
> as well.
> --
> Anith
>|||On Fri, 18 Nov 2005 13:53:12 -0500, Arthur Dent wrote:
>As example for clarification,
>ACTION is declared with a check as either D or P or Delivery or Pickup.
>I might have 5 rows where the ManifestID is <10>. What i want is to be able
>to say
>For All Rows Where MANIFESTID = 10,
>ACTION on ALL 5 Rows can be 'D' or 'P', but they ALL
>must be 'D' or ALL must be 'P'
Hi Arthur,
This might be one of those cases where a UDF + CHECK constraint will
work:
CREATE FUNCTION dbo.CheckNoOthers
(@.ManifestID int, @.Action char(1))
RETURNS char(3)
AS
BEGIN
DECLARE @.Result char(3)
IF EXISTS (SELECT *
FROM YourTable
WHERE ManifestID = @.ManifestID
AND Action <> @.Action)
BEGIN
SET @.Result = 'No'
END
ELSE
BEGIN
SET @.Result = 'Yes'
END
RETURN @.Result
go
ALTER TABLE YourTable
ADD CONSTRAINT NoOthers
CHECK (dbo.CheckNoOthers(ManifestID, Action) = 'Yes')
go
(untested - see www.aspfaq.com/5006 if you prefer a tested reply)
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Yah, that looks like it would probably work. Thanks!
"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:qgq1o1pc00til4dvnk7h2jk7nssscm6vk2@.
4ax.com...
> On Fri, 18 Nov 2005 13:53:12 -0500, Arthur Dent wrote:
>
> Hi Arthur,
> This might be one of those cases where a UDF + CHECK constraint will
> work:
> CREATE FUNCTION dbo.CheckNoOthers
> (@.ManifestID int, @.Action char(1))
> RETURNS char(3)
> AS
> BEGIN
> DECLARE @.Result char(3)
> IF EXISTS (SELECT *
> FROM YourTable
> WHERE ManifestID = @.ManifestID
> AND Action <> @.Action)
> BEGIN
> SET @.Result = 'No'
> END
> ELSE
> BEGIN
> SET @.Result = 'Yes'
> END
> RETURN @.Result
> go
> ALTER TABLE YourTable
> ADD CONSTRAINT NoOthers
> CHECK (dbo.CheckNoOthers(ManifestID, Action) = 'Yes')
> go
> (untested - see www.aspfaq.com/5006 if you prefer a tested reply)
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)
but im working in a legacy app here, and can't normalize the db because
it would break the existing apps around it.
I have a manifest table which essentially acts as both a header & line-items
table.
There is a MANIFESTID field which serves to link the lineitems together onto
one
manifest. There is also an ACTION field, which serves to indicate whether
the
manifest is for delivery or for pickup.
I dont know if it really is this hard, or if im just brain-freezing here,
but here is what
i'm trying to do... i want to put in some sort of constraint so that for all
the lines which
have any given MANIFESTID, the ACTION field is the same on all of them.
Thanks in advance,
- Arthur Dent.Not sure if I fully understood your problem, but in SQL Server, you cannot
create a constraint declaratively which can enforce some logic based on
multiple rows.
A general alternative is to use a after trigger with a rollback statement.
This is somewhat prohibitive in high performance systems since the logic can
turn out to be complex depending on your schema. In rare cases, you might be
able to work it out with a scalar udf used in a check constraint as well.
Anith|||As example for clarification,
ACTION is declared with a check as either D or P or Delivery or Pickup.
I might have 5 rows where the ManifestID is <10>. What i want is to be able
to say
For All Rows Where MANIFESTID = 10,
ACTION on ALL 5 Rows can be 'D' or 'P', but they ALL
must be 'D' or ALL must be 'P'
"Anith Sen" <anith@.bizdatasolutions.com> wrote in message
news:%23Y4JaqG7FHA.3544@.TK2MSFTNGP09.phx.gbl...
> Not sure if I fully understood your problem, but in SQL Server, you cannot
> create a constraint declaratively which can enforce some logic based on
> multiple rows.
> A general alternative is to use a after trigger with a rollback statement.
> This is somewhat prohibitive in high performance systems since the logic
> can turn out to be complex depending on your schema. In rare cases, you
> might be able to work it out with a scalar udf used in a check constraint
> as well.
> --
> Anith
>|||On Fri, 18 Nov 2005 13:53:12 -0500, Arthur Dent wrote:
>As example for clarification,
>ACTION is declared with a check as either D or P or Delivery or Pickup.
>I might have 5 rows where the ManifestID is <10>. What i want is to be able
>to say
>For All Rows Where MANIFESTID = 10,
>ACTION on ALL 5 Rows can be 'D' or 'P', but they ALL
>must be 'D' or ALL must be 'P'
Hi Arthur,
This might be one of those cases where a UDF + CHECK constraint will
work:
CREATE FUNCTION dbo.CheckNoOthers
(@.ManifestID int, @.Action char(1))
RETURNS char(3)
AS
BEGIN
DECLARE @.Result char(3)
IF EXISTS (SELECT *
FROM YourTable
WHERE ManifestID = @.ManifestID
AND Action <> @.Action)
BEGIN
SET @.Result = 'No'
END
ELSE
BEGIN
SET @.Result = 'Yes'
END
RETURN @.Result
go
ALTER TABLE YourTable
ADD CONSTRAINT NoOthers
CHECK (dbo.CheckNoOthers(ManifestID, Action) = 'Yes')
go
(untested - see www.aspfaq.com/5006 if you prefer a tested reply)
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Yah, that looks like it would probably work. Thanks!
"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:qgq1o1pc00til4dvnk7h2jk7nssscm6vk2@.
4ax.com...
> On Fri, 18 Nov 2005 13:53:12 -0500, Arthur Dent wrote:
>
> Hi Arthur,
> This might be one of those cases where a UDF + CHECK constraint will
> work:
> CREATE FUNCTION dbo.CheckNoOthers
> (@.ManifestID int, @.Action char(1))
> RETURNS char(3)
> AS
> BEGIN
> DECLARE @.Result char(3)
> IF EXISTS (SELECT *
> FROM YourTable
> WHERE ManifestID = @.ManifestID
> AND Action <> @.Action)
> BEGIN
> SET @.Result = 'No'
> END
> ELSE
> BEGIN
> SET @.Result = 'Yes'
> END
> RETURN @.Result
> go
> ALTER TABLE YourTable
> ADD CONSTRAINT NoOthers
> CHECK (dbo.CheckNoOthers(ManifestID, Action) = 'Yes')
> go
> (untested - see www.aspfaq.com/5006 if you prefer a tested reply)
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)
Subscribe to:
Posts (Atom)