How to input variable from input dialog into run query

Hi guys, can you help me. i use (input dialog) to input number week of year then this input number will be pass into Run Query


image

HI,

I recommend to use String.Format as the following.

strSQL ="SELECT TOP 1 Date
FROM Dim_Date
Where WeekOfYear ='{0}'
AND Year =2022
"

Then

String.Format(strSQL,MingguBerapa)

Regards,

hi, thanks for your reply but i want to dynamic input then pass into query
like this…
image

HI,

Can you try to replace the first assign with input dialog?

FYI, the following is a sample with validation for input text.

Sample20221122-2.zip (2.5 KB)

Regards,

Hi @Yoichi i’m sorry i cant open your workflows because my uipath version is lower than the template, mate.
Can you screenshot the condition code?

HI,

It’s as the following.

not Int32.TryParse(MingguBerapa,New Int32)  OrElse CInt(MingguBerapa)<0 OrElse CInt(MingguBerapa)>54

Regards,

I following th code and still get the erorr like this…
image

Regards.

HI,

Can you check the following downgraded sample?

Sample20221122-2v2.zip (2.4 KB)

And also can you check your query string as the following?

strSQL ="SELECT TOP 1 Date
FROM Dim_Date
Where WeekOfYear ='{0}'
AND Year =2022
"

strSQL =String.Format(strSQL,MingguBerapa)

Then check content of strSQL using WriteLine or MessageBox?

Regards,

I Mean i want to replace the 46 below with number from input dialog

Hi,

Did you check the above sample? If we input 46, the query string is as the following.

Regards,

yeah i try it but the string WeekOfYear output is like this…

and i mean want to ouput like this… because the date want to continue the program using parse exact
image

Hi,

Your 1st image seems no problem. (2nd image cannot be seen due to forum system trouble) Please set this variable to query property?
Or is there any issue to set this variable?

Regards,

here the 2nd image (output that i want)

my project is i want input the WeekOfYear with the (input dialog box), then this number will dynamically fill in the (run query) when calling the date in SQL server table.

for example: in the dialog box I input WeekOfYear = 46. then the output will be 11/06/2022 00:00:00

HI,

Alright, we can get query string which contains week number from InputDialog. Is this no problem, isn’t it?

image

Or, do you need to calculate date from week number before sending the query?

Regards,

can this output make to datatable and printout date format? (11/06/2022 00:00:00)
because the output is format date from datatable. and i will converti it using parse exact

or can i copy this result to Run Query sql syntax?

Hi,

Do you need to convert from week number to start date of the week? If so, the following will help you. Please note that we need to determine which year to calculate.

Sequence2.xaml (6.8 KB)

Regards,

1 Like

This is work @Yoichi thank you mate. You the best. :wink:

1 Like

Hi @Yoichi . how to make this code to parse exact?
i want to use the output to pick/select date dynamic

HI,

As the following expression returns DateTime type, we need to use ParseExact if your input is this.

dateJan1.AddDays(7*(weekNumber-1)-CInt(dateJan1.DayOfWeek))

We can create datetime string from this datetime variable.

varDateTime = dateJan1.AddDays(7*(weekNumber-1)-CInt(dateJan1.DayOfWeek))

Then

varDateTime.toString("yyyyMMdd")

Or do you paarse from any other string?

Regards,