expression

convert ssis expression datetime to int

微笑、不失礼 提交于 2020-01-04 01:51:30
问题 I want to calculate last friday's date in ssis. Below code is doing it. DATEADD("dd", -1 - (DATEPART("dw", getdate()) % 7), getdate()) But it gives results for datetime datatype and I want results for int data type in ssis. How to convert? DATEADD("dd", -1 - (DATEPART("dw", getdate()) % 7), getdate()) 回答1: According to this Microsoft article: When a string is cast to a DT_DATE, or vice versa, the locale of the transformation is used. However, the date is in the ISO format of YYYY-MM-DD,

convert ssis expression datetime to int

走远了吗. 提交于 2020-01-04 01:51:13
问题 I want to calculate last friday's date in ssis. Below code is doing it. DATEADD("dd", -1 - (DATEPART("dw", getdate()) % 7), getdate()) But it gives results for datetime datatype and I want results for int data type in ssis. How to convert? DATEADD("dd", -1 - (DATEPART("dw", getdate()) % 7), getdate()) 回答1: According to this Microsoft article: When a string is cast to a DT_DATE, or vice versa, the locale of the transformation is used. However, the date is in the ISO format of YYYY-MM-DD,

sizeof an integer expression in C

白昼怎懂夜的黑 提交于 2020-01-03 18:58:51
问题 To my semi-surprise with Xcode compiling C (gnu11) #include <stdio.h> int main(int argc,char**argv) { short s = 1; printf( "%zd %zd %zd\n", sizeof(s), sizeof(s*s), sizeof(s?s:s)); return 0; } Produces the output 2 4 4 I was expecting 2 2 2 or possibly 2 4 2 Why is this? 回答1: I recalled from K&R that any integer expression smaller than an int is promoted to int. I found this in Standard (C89): 3.2.1.1 Characters and integers A char, a short int, or an int bit-field, or their signed or unsigned

Shorthand expression for an if ( $a == $b || $a == $c ) statement

不问归期 提交于 2020-01-03 15:37:14
问题 I know this code will work: echo ( $a == $b || $a == $c ) ? "Yes" : "No"; That can be read like: if $a is equal to $b or $a is equal to $c Is there a way to make it more shorter like: if $a is equal to $b or $c I have tried a lot including this but still no luck: echo ( $a == ( $b xor $c ) ) ? "Yes" : "No"; 回答1: You can use in_array: var_dump(in_array($a, [$b, $c])); with your example: echo in_array($a, [$b, $c]) ? 'Yes' : 'No'; Note: this syntax is only useful if you have more than 2 values.

Splitting input string for a calculator

佐手、 提交于 2020-01-03 15:24:09
问题 I'm trying to split the input given by the user for my calculator. For example, if the user inputs "23+45*(1+1)" I want to this to be split into [23,+,45,*,(,1,+,1,)]. 回答1: What your looking for is called a lexer . A lexer splits up input into chunks (called tokens ) that you can read. Fortunately, your lexer is pretty simple and can be written by hand. For more complicated lexers, you can use flex (as in "The Fast Lexical Analyzer"--not Adobe Flex), or (since you're using Java) ANTLR (note,

How can I use “OR” condition in MySQL CASE expression?

这一生的挚爱 提交于 2020-01-03 10:56:13
问题 I have a procedure that contains CASE expression statement like so: BEGIN .... WHILE counter < total DO .... CASE ranking WHEN 1 OR 51 OR 100 OR 167 THEN SET project_name = 'alpha'; WHEN 2 THEN SET project_name = 'beta'; WHEN 10 OR 31 OR 40 OR 61 THEN SET project_name = 'charlie'; .... ELSE SET project_name = 'zelta'; END CASE; INSERT INTO project (id, name) VALUES (LAST_INSERT_ID(), project_name); SET counter = counter + 1; END WHILE; END $$ DELIMITER ; When I call the above procedure, cases

Replacing digits with str.replace()

混江龙づ霸主 提交于 2020-01-03 09:04:14
问题 I want to make a new string by replacing digits with %d for example: Name.replace( "_u1_v1" , "_u%d_v%d") ...but the number 1 can be any digit for example "_u2_v2.tx" Can I give replace() a wildcard to expect any digit? Like "_u"%d"_v"%d".tx" Or do I have to make a regular expression? 回答1: Using regular expressions: >>> import re >>> s = "_u1_v1" >>> print re.sub('\d', '%d', s) _u%d_v%d \d matches any number 0-9. re.sub replaces the number(s) with %d 回答2: You cannot; str.replace() works with

.htaccess regular expression issue

妖精的绣舞 提交于 2020-01-03 05:58:13
问题 I still have no answer about this so I'm posting it here. I want to match an url in the form of root/language/sub/.../document in a .htaccess file and then rewrite it as root/sub/.../document.php?lang=language Im close to hit but it seems my regexp doesn't 'catch' the input url. Here it is : RewriteCond %{REQUEST_FILENAME} !-d RewriteCond ^[a-z]{2}.*$/%{REQUEST_FILENAME}\.php -f RewriteRule ^([a-z]{2})/(.*)$ $2.php?lang=$1 Can someone point me out what is wrong here ? I'm no expert in regexp

Implication of using dynamic Expression<Func<T,X>> in NHibernate

♀尐吖头ヾ 提交于 2020-01-03 02:56:14
问题 Basically in my application, I am using the following code to build my expression depending on the selection on the page. Expression<Func<T, bool>> expr = PredicateBuilder.True<T>(); expr = expr.And(b => b.Speed >= spec.SpeedRangeFrom && b.Speed <= spec.SpeedRangeTo); ... It has the tendency to end up with a long expression with multiple "or" and "and" conditions. Once I have finished building the expression, I passed it on to my repository which looks like the following: var results =

Including variables in expression call in R

蓝咒 提交于 2020-01-03 02:47:05
问题 I was wondering if it were possible to include variables when using expression in R. For instance I would like to do something like this: par(mfrow=c(2,3)) for (i in 1:6) { plot(x, p1-i*p2, main=expression(Phi[1] - i * Phi[2])) } But this does not work, as it prints Φ 1 - iΦ 2 (i.e. it does not substitute i with 1, 2, ... 6 回答1: Use substitute: > substitute(Phi[1] - i* Phi[2], list(i = i)) Phi[1] - 3 * Phi[2] 回答2: Looks like it uses the variables. I set x = 1 and used the following. > p1 =