produce leading 0 in the minutes field - tsql

This snippet:
select Datename(hh,DATEADD(HH, -5, [time])) + ':' + Datename(mi,[time])....
will produce:
11:4
But i need the leading '0' in front of the '4'.

You can pad the minutes with leading zeros, and then take the right two characters:
SELECT Datename(hh,DATEADD(HH, -5, [time])) + ':' +
right('00' + Datename(mi,[time]), 2)

declare #hoje datetime = getdate()
select #hoje,format(#hoje,'HH') +':' + format(#hoje,'mm')

Related

Crystal report make string bold

I need to make the first string in this formula bold, can anyone help with this?
I am posting below a single fragment of the formula first and after the full formula including the fragment, appreciate all the help.
string in question:
if ({IIS_EPC_EML_MDOC.cardname}) <> "" then
InvAddr:=InvAddr + chr(13) + {IIS_EPC_EML_MDOC.cardname} + ChrW(13) ;
full formula:
WhilePrintingRecords;
Local StringVar InvAddr;
InvAddr:="";
if ({IIS_EPC_EML_MDOC.cardname}) <> "" then
InvAddr:=InvAddr + chr(13) + {IIS_EPC_EML_MDOC.cardname} + ChrW(13) ;
if not isnull({IIS_EPC_EML_MDOC.address}) then
InvAddr:=InvAddr + {IIS_EPC_EML_MDOC.address} + ChrW(13);
//if not isnull({IIS_EPC_EML_MDOC.VatNo}) then
// InvAddr:=InvAddr + 'VAT No:'+{IIS_EPC_EML_MDOC.VatNo};
//Add EORI Number
if ({IIS_EPC_EML_MDOC.BPEORINumber}) <> "" then
InvAddr:=InvAddr + chr(13) + "EORI No.: " + {IIS_EPC_EML_MDOC.BPEORINumber};
//Add VAT Number
if ({IIS_EPC_EML_MDOC.vatno}) <> "" then
InvAddr:=InvAddr + chr(13) + "VAT No.: " + {IIS_EPC_EML_MDOC.vatno};
//Strip out trailing blank spaces from address block
while instr(InvAddr," "+Chr(13)) > 0 do
(
InvAddr:=Replace(InvAddr," "+Chr(13),Chr(13));
);
//Strip out blank lines from address block
while instr(InvAddr,Chr(13)+Chr(13)) > 0 do
(
InvAddr:=Replace(InvAddr,Chr(13)+Chr(13),Chr(13));
);
InvAddr
best Regards,
Daniel
One option is to construct the text as HTML with bold text where you desire.
Then, right-click the formula,
select Format Field...
Select 'Paragraph' tab
and set 'Text Interpretation' to 'HTML text'.

Separator for five or more digits number in Tableau

I was working on a Tableau Project. We want to have a separator for five or more digits numbers.
For ex:-
1 as 1
12 as 12
123 as 123
1234 as 1234
12345 as 12,345
123456 as 1,23,456
Can you please assist me, how to achieve this?
I am nearly sure that this cannot be done as long as numbers are formatted as numbers. However, as a workaround, I have developed a method which however will convert numbers to string. Let's say you have a column col of desired numbers
copy your column say col2 (save original for future use) and convery type to string
Create a new calculated field say desired by using this calculation
If LEN([Col2]) <= 4 THEN
[Col2]
ELSEIF LEN([Col2]) < 6 THEN
REPLACE([Col2], RIGHT([Col2], 3), "") + "," +RIGHT([Col2], 3)
ELSEIF LEN([Col2]) <8 THEN
REPLACE([Col2], RIGHT([Col2], 5), "") + "," +
REPLACE(RIGHT([Col2],5), RIGHT([Col2], 3), "") + "," +RIGHT([Col2], 3)
ELSE
REPLACE([Col2], RIGHT([Col2], 7), "") + "," +
REPLACE(RIGHT([Col2],7), RIGHT([Col2], 5), "") + "," +
REPLACE(RIGHT([Col2],5), RIGHT([Col2], 3), "") + "," +RIGHT([Col2], 3)
END
this CF will work exactly as desired for upto 9 digits.
Alignment is not a big problem, if considered

SSRS subtract 1 day when using calender

I'm trying to get the correct date from calendar using expression. But with my code, it gives 32 days and I need 31 days. How can I use DateAdd with this?
="Date: " + cstr(left(Parameters!KP2Ky.Value, 4) + "." + Mid(Parameters!KP2Ky.Value, 5, 2)+ "." + Right(Parameters!KP2Ky.Value,2))
I tried but I couldn't figure out how you are getting 32 in your result.
I would make the parameter a DATE type.
For the last day of the month previous to the selected month, you could use
="Date: " & FORMAT(DATEADD("d", 0 - DAY(Parameters!KP2Ky.Value), Parameters!KP2Ky.Value), "yyyy.MM.dd")
The last day of the selected month is a little more complicated:
="Date: " & FORMAT(DATEADD("d", 0 - DAY(DATEADD("M", 1, DATEADD("d", 1 - DAY(Parameters!KP2Ky.Value), Parameters!KP2Ky.Value))), DATEADD("M", 1, DATEADD("d", 1 - DAY(Parameters!KP2Ky.Value), Parameters!KP2Ky.Value))), "yyyy.MM.dd")

IIF Condition Ques

Can someone explain this condition, because I'm getting wrong Time data eg : I'm expecting sch departure time as 15.10 but I'm getting 15.01
[Sch Dep Time] = IIF(DATEPART(Hour,[Journey and Details.schdeptime]) < 10 AND DATEPART(Minute,[Journey and Details.schdeptime]) < 10,
('0' + DATEPART(Hour,[Journey and Details.schdeptime]) + ':0' + DATEPART(Minute,[Journey and Details.schdeptime])),
IIF(DATEPART(Hour,[Journey and Details.schdeptime]) < 10,
('0' + DATEPART(Hour,[Journey and Details.schdeptime]) + ':' + DATEPART(Minute,[Journey and Details.schdeptime])),
(DATEPART(Hour,[Journey and Details.schdeptime]) + ':0' + DATEPART(Minute,[Journey and Details.schdeptime]))))
Update
It suddenly hit me that [Sch Dep Time] should contain the time component of the dataTime value stored in [Journey and Details.schdeptime], in a minute resolution. For that, you don't need to mess around with specific date parts and string concatenation, all you have to do is use convert:
[Sch Dep Time] = CONVERT(char(5), [Journey and Details.schdeptime], 108)
The 108 style returns hh:mm:ss (24 hours), and by using char(5) you are just taking the first 5 chars of that string - hh:mm.
First version
You have overcomplicated things. Try using the old right('00' + val, 2) trick instead:
[Sch Dep Time] = RIGHT('00' + CAST(DATEPART(Hour,[Journey and Details.schdeptime]) AS VARCHAR(2)), 2) + ':' +
RIGHT('00' + CAST(DATEPART(Minute,[Journey and Details.schdeptime]) AS VARCHAR(2)), 2)
Exlpanation:
You start off by concatenating leading zeroes to the string you want.
Suppose you have a string representing a number that must always have 4 digits, but it might be 1234 or 0003 - so you start by doing '0000' + #YourNumber.
Then, you use RIGHT to trim off any unwanted zeros - suppose you now have 000023, but you want 0023 - you do RIGHT('000023', 4) to get the last 4 chars.

Hash Alphanumeric string to a 16 Byte Hex String

I need a hash algorithm that takes a 28 character alphanumeric [a-zA-Z0-9] string and outputs a 16 Byte Hex UUID.
Example: hash("cVoFfGI0vhfvWD61Hh1QTsmUJRT2") = 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6
Is there a way to do so using md5 or SHA1?
Thanks.
EDIT 1 :
The alphanumeric string has a fixed length of 28 characters.
here a solution in javascript (nodeJS)
var crypto = require('crypto');
function hash(input) {
var s = crypto.createHash('md5').update(input).digest("hex");
return s.substr(0, 8) + '-' + s.substr(8, 4) + '-' + s.substr(12, 4) + '-' + s.substr(16, 4) + '-' + s.substr(20, 12);
}
hash('cVoFfGI0vhfvWD61Hh1QTsmUJRT2');