I have two columns "ID_TT" in select values 1 and "ID_ARC" in select values 2.
ID_TT has below values
[blank]
121
[blank]
ID_ARC has below values
146
[blank]
171
I need to merge these two . I used calculator but it does not work. How can we solve this.
output must be
146
121
171
Here is the solution. I think its useful to you
If you follow above step you can get that result like these.
Result:
Thank you.
Related
Hi I have one table and one input number. based on which I need an output like mentiones below.
TABLE: tab
col1. col2
113. 568
123. 456
456. 789
789. 102
345. 987
102. 890
890. null
Input Number: 789
Output:
ouput_col
102
890
456
123
Please help me to get a right SQL query or procedure which will give me desired output based on the provided input number. It should be generic query work for data larger than this, which can check backward and forward interlinked data and returns all in a single column as mentioned in output_col. Thanks in advance.
I update a View to get in two columns the same value, but it interchanges the two values instead of just setting it. My (reduced for so) view UpdateADAuftrag2 is this.
SELECT dbo.CSDokument.AD1, dbo.UpdateAS400zuSellingBenutzer2.BenutzerNr
FROM dbo.AS400Auftrag
INNER JOIN
dbo.CSDokument ON dbo.AS400Auftrag.Angebotsnummer = dbo.CSDokument.Angebotsnummer
INNER JOIN
dbo.UpdateAS400zuSellingBenutzer2 ON dbo.AS400Auftrag.AD = dbo.UpdateAS400zuSellingBenutzer2.SchluesselWert
AND
dbo.CSDokument.AD1 <> dbo.UpdateAS400zuSellingBenutzer2.BenutzerNr
WHERE (dbo.AS400Auftrag.AD IS NOT NULL)
The important part is dbo.CSDokument.AD1 <> dbo.UpdateAS400zuSellingBenutzer2.BenutzerNr
AD1 is user number for external workers and BenutzerNr means user number. So e.g. the person Charlie Brown is an external worker and has the user number 31. When in AD1 is 31 - Charlie Brown is the external worker for this document (order in this case).
The Update statement loos like this
UPDATE [dbo].[UpdateADAuftrag2]
SET [AD1] = [BenutzerNr]
I have for example these values
AD1 | BenutzerNr
31 | 54
99 | 384
112 | 93
after the update the result is this
AD1 | BenutzerNr
54 | 31
384 | 99
93 | 112
Why not this?
AD1 | BenutzerNr
54 | 54
384 | 384
93 | 93
edit: UpdateAS400zuSellingBenutzer is also a View, but as far as I can see it includes only BenutzerNr and not AD1.
Firstly, you're never going to see your expected results in the view. Your UPDATE statement is effectively a DELETE statement (as far as the view is concerned). Rows only appear in the view if AD1 <> BenutzerNr, but you're setting them to be equal.
However, the documentation for updatable views states "Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table." Your update statement references columns from more than one table.
https://msdn.microsoft.com/en-us/library/ms187956.aspx#Updatable Views
I'm not sure what you're trying to achieve here, but in my experience it's usually easier to issue the UPDATE statement against the base tables directly.
There were 2 bugs - Bug 1 View UpdateAS400zuSellingBenutzer2 had 2 results sometimes for one entry in CSDokument and Bug 2 There were 2 entries in Table AS400Auftrag and then it switched between these two entries. So it just looked like the SET switched the two entries but it was just by chance. Thanks for reading.
I've been trying to figure this out for a little bit now and i keep running into dead ends. Maybe someone here can help me. I work for a company and we are going to be receiving a file for units we are going to repair. In certain situations, we receive one claim for repair that has multiple units contained within it. I only have one field to import the serial number and I need to combine how ever many rows there is for a specific claim.
For example the file I would get would look like:
ClaimNumber SerialNumber
555 12345
555 123456
555 1234567
556 4321
557 3421
558 9876
558 98765
So i need to export this table combining the serial numbers into one field like:
ClaimNumner SerialNumber
555 12345, 123456, 1234567
556 4321
557 3421
558 9876, 98765
I am limited on receiving the file in this format, so this is all i have to work with. There are other fields in the file but i think these are the ones that I should be looking at. let me know if anyone has any ideas. Thanks!!
Given that your table is named Claim, then I think this should do it, (not tested)
Select Main.ClaimNumber,
Left(Main.Serials,Len(Main.Serials)-1) As "Serials" From(Select distinct T2.ClaimNumber,
(Select T1.SerialNumber + ',' AS [text()]
From Claim T1
Where T1.ClaimNumber = T2.ClaimNumber
ORDER BY T1.ClaimNumber
For XML PATH ('')) [Serials]
From Claim T2) [Main]
I am designing a system containing logical steps with some actions associated (but the actions are not part of the question, but they are crucial for each step in the list)!
The ting is that I need to create a way to define all the logical steps in an ordered way, so that I can get the list by query, and also make modifications later on!
Anyone with some experience in this kind of database design?
I have been thinking of having a column named wizard_steps (or something similar), and then use priority to make the order, but for some reason i feel that this design at some point will fail (due to items with same priority, adding new items would then have to rearrange the rest of the items, and so forth)!
Another design I have been thinking about is the use of "next item" as a column in the wizard_step column, but I don't feel this is the correct step eighter!
So to summarize; I am trying to make a list (and the design should be open enought to support multiple lists) of elements where the order is crucial!
Any ideas on how the database should look like?
Thanks!
EDIT: I found this yii component I will check out: http://www.yiiframework.com/extension/simpleworkflow/
Might be a good solution!
If I get you well, your main concern is to create a schema that supports ordered lists and can provide easy insert/reordering of items.
The following table design:
id_list item_priority foreign_itemdef_id
1 1 245
1 2 32
1 3 45
2 1 156
2 2 248
2 3 127
coupled to a table with item definition will be easily queried but will be difficult to maintain, especially for insertions
That one:
id_list first_item_id
1 45
2 38
coupled to the linked list:
item_id next_item foreign_itemdef_id
45 381 56
381 NULL 59
38 39 89
39 42 78
42 NULL 45
Will be both difficult to query and update (you should update the linked list inside a transaction, otherwise your linked list can get corrupted).
I would prefer the first solution for simplicity.
Depending on your update frequency, you may consider using large increments between item_priority to help insertion:
id_list item_priority foreign_itemdef_id
1 1000 245
1 2000 32
1 3000 45
2 1000 156
2 2000 248
2 3000 127
1 2500 46 -- late insertion
1 2750 47 -- late insertion
EDIT:
Here's a query that will hopefully make room for an insertion: it increments priority of all rows above the argument
$query_make_room_for_new_item = "UPDATE item_priority_table SET item_priority = item_priority + 1 WHERE item_priority > ". $new_item_position_priority ." AND id_list = ".$id_list;
Then insert your item with priority $new_item_position_priority
Guys, I'm new at SQL and can't figure out the "right way" to do the last part of a query. I have a table which contains a list of items and their equivalents. There are essentially twice as many rows as needed, and I'm trying to find a SQL way to select 1/2 of the entries so there are no duplicates.
Starting Table with duplicates:
Item Name EquivItem
---- ------ ----------
100 bubba 106
103 gump 109
106 shrimp 100
109 grits 103
And the resulting table would be:
Item Name EquivItem
----- ----- ----------
100 bubba 106
103 gump 109
I was using a couple nested loops in sequential code to filter out the duplicates, but finally wrote a query that works but feels like a hack.
I'm arbitrarily using a WHERE (Item < EquivItem) to select only one of the rows. The actual tables are a bit more complex and I'm afraid there may be a case where this doesn't work.
SELECT *
FROM T
WHERE Item < EquivItem
I'm trying to take some time to figure out the right way to do things before I develop too many bad habits. Any suggestions? Thanks.
Is it possible for more than two items to be equivalent, such as 100 = 103 = 106? Can this happen?
Item Name EquivItem
---- ------ ----------
100 bubba 103
103 gump 106
106 shrimp 103
As long as the the equivalents can't be chained together, and always have a 1-to-1 relationship, your solution looks perfectly fine to me.
If this scenario can happen, I would first scrub the data to make sure that all the EquivItems refer to the lowest Item ID in the chain... and then your original query would still do the job.