Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I need to create three random id between the max ID of the table and the min ID of the table. How can I do that in Sql?
You need to use two variables to store Min and Max primary keys. let's say #a and #b.
then using below query you can get your random number
declare #a int,#b int
select #b=max(id),#a=min(id)
from mytbl
SELECT FLOOR(RAND()*(#b-#a)+1)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 days ago.
Improve this question
On Synapse Analytics how do we - Convert a Time datatype column with values from hh:mm:ss.ffffff to hh:mm:ss:ff
Here are the samples:
Actual
00:00:00.9900000
00:26:10.0200000
00:00:03.9800000
00:22:41.0400000
00:00:00.9800000
00:22:09.0300000
00:00:00.9900000
00:25:34.0200000
00:19:26.9800000
00:03:45.0200000
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 days ago.
Improve this question
I need to return row numbers for consecutive dates for each activity.
enter image description here
I have tried row_number() over(partition by) but cannot seem to get the right row numbers against the consecutive dates for the activity type. This is what I am trying to return:
enter image description here
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 11 months ago.
Improve this question
I want to display the only the highlighted values (They are 9 digits). Can we do this using RegExp?
You can use regexp_substr(column1, '[0-9]{9}'). Below is an example:
select regexp_substr(column1, '[0-9]{9}') nine_digits
from (values
(';**260488570**;1;13.25;20339=22.99')
,('1293=::info::0,;**297100755**;1;2.86;20339=4.49')
,('1293=::info::0,;**338010030**;3;6.71;20339=2.69')
,('1293=::info::0,;**260142941**;1;2.38;20339=4.59')
,('1293=::info::0,;**370039059**;1;2.86;20339=3.79')
);
Result:
COL2
260488570
297100755
338010030
260142941
370039059
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Should be an easy convert, but cast and convert are failing me.
The value I am trying to convert is: 1509180600
Other examples are 1572256200, 5150938920
I have a very large number of records and many fields where dates have been stored like this. The system is being replaced, which means thankfully, this problem will go. But need to know what the values are before wiping them!
This is probably a Unix timestamp. You can convert it by adding seconds to 1970-01-01:
select dateadd(second, col, '1970-01-01')
. . .
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a table which store Customerid, amount and vouchartype this is a transaction table which store multiple entry for a single customer. vouchartype is 'D' for debit and 'C' for Credit and all amount have positive value. Now I want to sum of Individual customer debit value should be subtract from Credit value.
Please help me
Here is one solution. Everything other than 'C' is considered positive. You might need to reverse the sign depending on what you need.
SELECT
Customerid,
sum(case when vouchartype = 'C' THEN -amount ELSE amount END) As AMount
FROM YOurTable
GROUP BY Customerid