Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inserting value(1000) in default value On a specific date 1

Status
Not open for further replies.

pcwaleed

Programmer
Oct 7, 2014
29
IQ
Hello,,,
I need insert value(1000) in default value On a specific date where (date-sal)= 01-07-2017 and 01/01/2017
foxpro_rghfhn.jpg
 
I can't see any problem in what you are trying to do.

A default value can be any legal VFP expression. The only rule is that it must return the same data type as the parent field. Since your expression returns a numeric value, and the field in question (taba) is also numeric, it should work as expected.

What problem are you seeing? Is there an error message?

That said, while it should work for INSERT, it probably won't do what you want with APPEND BLANK, as the dependent field (date_sal) won't have a value at the point where the default kicks in.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
yes, the massege return error, can you tell me the right massege for this function
 
the message==
iif(date_sal=date(01/07/2017),1000,0)
 
Read the help topic on Date():
What you call message is your default value expression. With "message", Mike meant the error message you get displayed when trying to set that default value expression, but it helps to see the full expression, too, as the screenshot cuts that off and the selected line is unreadable for me on my large display, much too small. So thanks for that essential info, it always helps to provide code as text and not screenshot.

You simply make the wrong usage of the date() function, I initially linked to the definition you'd need to use.

A date literal - a date value needing no function like DATE() to be created - also is possible, that would have the format {^YYYY-MM-DD} in VFP, so perhaps the shortest possible way to do that is:
[tt]iif(date_sal={^2017-07-01},1000,0)[/tt]

Your initial post indicates you want this for two dates, also for 01/01/2017, that could be done with an ICASE, which would also allow assigning different default values per date:
[tt]icase(date_sal={^2017-07-01},1000,date_sal={^2017-01-01},1000,0)[/tt]
or for the same default you may use
[tt]iif(date_sal={^2017-07-01} OR date_sal={^2017-07-01},1000,0)[/tt]

But surely you will not use
[tt]iif(date_sal={^2017-07-01} AND date_sal={^2017-07-01},1000,0)[/tt]
or
[tt]iif(date_sal={^2017-07-01} AND {^2017-07-01},1000,0)[/tt]

If you have any legacy VFP background, what you had in mind when you wrote date(01/07/2017) might have been CTOD('01/07/2017'), but I would not recommend that, as it depends on settings, different countries have different formats for dates, not only in the order of day and month. {^YYYY-MM-DD} is a universal way to write a date independent of such regional differences.

Bye, Olaf.
 
iif(date_sal=date(01/07/2017),1000,0) is wrong syntax for date(). Use

[pre]iif(date_sal=date(2017,1,7),1000,0)[/pre]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top