December 13, 2019 at 3:51 pm
Hi All,
I have table which stores all in single column, I want to take a data only for particular vendor name along with the server name where the tool is installed.
Like,
Server name, Tool Name
----
CREATE TABLE [dbo].[result](
[id] [int] IDENTITY(1,1) NOT NULL,
[Data] [nvarchar](255) NULL,
[Item] [nvarchar](255) NULL
)
insert into [result] values ('server:server1','server')
insert into [result] values ('Name : VM Tool','Name')
insert into [result] values ('Version : 10.0.9.3917699','Version')
insert into [result] values ('Vendor : VMware, Inc.','Vendor')
insert into [result] values ('Caption : VMware Tools','Caption')
insert into [result] values ('server:server1','server')
insert into [result] values ('Name : VS studio','Name')
insert into [result] values ('Version : 10.0.9.3917699','Version')
insert into [result] values ('Vendor : MS','Vendor')
insert into [result] values ('Caption : MS VS','Caption')
insert into [result] values ('server:server1','server')
insert into [result] values ('Name : VS studio','Name')
insert into [result] values ('Version : 10.0.9.3917699','Version')
insert into [result] values ('Vendor : MS','Vendor')
insert into [result] values ('Caption : MS VS','Caption')
December 13, 2019 at 4:11 pm
Apologises if I missed something but where is the link between each vendor and server name? The only link I can see is the order of the insert statements. Unfortunately you can't guarantee that SQL will return the results in the same order. Unless I've misunderstood you need another column to specify which rows of data are part of the same vendor/software combination.
I am not intending to criticise, I only ask the question to understand.
If possible you may be better with a different table design which has specific columns for server, name, version e.t.c. How much control do you have over the table design?
December 13, 2019 at 4:18 pm
Thanks for reply, We just got this as excel and loaded into a database. I am trying to get data
Server name, Tool Name
server1, VM
Server1, VS studio
Server2, SQL server
December 13, 2019 at 4:26 pm
as1981 is right - there is nothing to link the server name to the tool name. A table is an unordered set, so SQL Server can't assume that "VM" goes with "server1" just because it appears in the next row. If this comes from a spreadsheet, have you tried pivoting in Excel before loading into the database?
John
December 13, 2019 at 5:03 pm
Thanks. I will have a look on it.
December 13, 2019 at 6:45 pm
If the inserts are done in a particular order and the order is actually preserved by the ID column, this could be pretty easy to pull of. You just need that guarantee as to order.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 13, 2019 at 7:05 pm
Sqltester1: Jeff Moden is correct. Sorry I didn't think of the possibility of using the ID column. Perhaps let us know if you are able to pivot the data in Excel?
If you still need to use the database to create the pivot have you been able to try any queries?
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply