Displaying My Querry Horizontally
Feb 22, 2008Is there a way to display my querry horizontally?
View 2 RepliesIs there a way to display my querry horizontally?
View 2 RepliesIn sql server, multiple instances of data default to a row display or vertical. I need a set of data in sql2005 to view horizontally so I can us it in a crystal report. Here is my issue.
gift.HonorKey, gift.HonorName, gift.HonorId
1211 Smith 1222
1244 Owens 4155
I need for the data to read like this:
HonorKey1, HonorKey2, HonorName1, HonorName2, HonorId1, Honorid2
1211 1244 Smith Owens 1222 4155
the table name is gift_view
I would like to be able to create a view in sql analyzer, then save as an SQL View
My direct email is jackfam@comcast.net
I would like for each of the queries to have all of the selected fields shown horizontally in one table.
For example,
Commercial Created | Commercial Closed | Commercial UserId | Residential Created | Residential Closed | Residential UserId | Other Created | Other Closed | Other UserId.
Here is what I have now and it is displaying the fields as I would like them to. In the code below, each Views is acting as an individual table and then joined together to make another table when the query is executed.
WITH t1 AS (
SELECT vSalesReportProcessDetail.[RequestId]
,vSalesReportProcessDetail.Process
,vSalesReportProcessDetail.Entered
,vSalesReportProcessDetail.Closed
/*ROW_NUMBER() over (ORDER BY vSalesReportProcessDetail.[RequestId]) rn*/
FROM[Sales].[dbo].[vSalesReportProcessDetail]
WHERE Process = 'Commercial' ),
[code]....
I have a table where the ID column is a forign key as shown below:
select * from Joel_Table
IDID_Value
1One
2Two
3Three
1Four
2Five
3Six
1Seven
2Eight
3Nine
1Ten
Now, I order the result set based on the ID column:
select ID, ID_Value from Joel_Table
group by ID, ID_Value
order by ID, ID_Value
IDID_Value
1Four
1One
1Seven
1Ten
2Eight
2Five
2Two
3Nine
3Six
3Three
I want though to order the result set as one ID per row:
ID ID_Value ID_Value ID_Value ID_Value
1 Four One SevenTen
2 Eight Five Two
3 Nine Six Three
What is the best way of accomplishing this task?
Thank you much in advance -
My project is to automate testing of Stored Proceduresof type SELECT (at least for now).I want to create a table where each stored procedure'sinput parameter values are entered and in another tablethe expected result value(s) are entered when executedagainst a sample database containing manually enteredand verified data.My current problem is that the stored procedures' inputparameters range from none to 50 parameters (ok nowthat I think of it maybe this SP with 50 parameters is anINSERT SP; regardless let's assume I have SPs thatrequire 10-20-30+ parameters).My other problem is each stored procedures' returnedresult could fall into any of these four categories:- 1 row, 1 column- 1 row, many columns- many rows, 1 column- many rows, many columnsSo far I thought about 3 ways of storing the data:1- 1 large table with 50 columns that can hold variousnumber of input parameter values. Similar type of table forholding the output result for the four categories above.2- 1 small table holding one value per row. All kinds of joinswith other tables to indicate which SP and which column thevalue belongs to...3- 1 individual table per stored procedure, this way the numberof columns in the table would match exactly the number of inputparameters.Obviously the above 3 categories could apply both for the inputand output data.Now I'm still in research mode and I haven't decided on any choiceyet. And I know each approach has serious consequences; let's justsay they are all with some limitations.Has anyone dealt with this scenario before? This is the first time Ineed a table to hold various types of returned data.Just to give some numbers: possibly a few thousand SPs and verylikely each SP would have more than one test scenario.What would you suggest?Thank you
View 2 Replies View RelatedIs it possible to merge cells within several columns depending on the row number?
e.g.
colA colB colC colD
1 x a b c
2 y -------------------------
3 z -------------------------
for row # 2, #3, colB colC colD are merged.
sample results: <MRNID=10002><VesselCode=VSL1>
wherein MRNID and VesselCode are primary keys of the table.
Is it possible to combine the following tables:
Table1:
id
1
2
3
Table2:
licenses
3
2
1
To one table, like this:
id licenses
1 3
2 2
3 1
-There is always the same number of rows in both tables.
Thanks a lot!
I'm trying to append rows horizontally - I'm using the "xml path" approach
SELECT
E.[USER_NAME] As 'User Name',
(
SELECT ',' + C.[PERMISSION_NAME]
FOR XML PATH('')
) As [Associated Groups]
FROM TABLEA As A
JOIN TABLEB AS B ON A.PK_OBJ_ID = B.FK_APP_OBJECT_REF
JOIN TABLEC AS C ON C.PK_PERMISSION_ID = B.FK_PERMISSION_REF
JOIN TABLED AS D ON D.FK_PERMISSION_REF = C.PK_PERMISSION_ID
JOIN TABLEE AS E ON E.PK_PERSONNEL_ID = D.FK_PERSONNEL_REF
WHERE A.[OBJECT_NAME] = 'MyObjectName'
It's not working. I'm getting:
User nameAssociated Groups
A. SmithG1
A. SmithG2
A. SmithG3
etc...
What I'm looking for is:
User NameAssociated Groups
A. SmithG1, G2, G3
etc...
Hello,
I have a very wide report that uses a table control. I would like to "freeze" the two leftmost columns so that they remain visible when the user is scrolling horizontally (sideways). Is this possibe?
Thanks,
BCB
Hi,
I have a client with the following table structure:
ItemNumber, Name, Description
containing the following Data (example):
ItemNumber
Name
Value
6473764
SDRAM
4GB
6473764
Xeon
2300 Mhz
6473764
Video
256 MB
6473764
Bus
1300 Mhz
6473759
SDRAM
2GB
6473759
Xeon
2000 Mhz
6473759
Video
128 MB
6473759
Bus
1066 Mhz
I am trying to use PIVOT to convert this into Columns:
Item Number
SDRAM
Xeon
Video
Bus
6473764
4GB
2300 Mhz
256 MB
1300 Mhz
6473759
2 GB
2000 Mhz
128 MB
1066 Mhz
The problem is that I do not know the names of the columns before I run the query. I retrieve them based on a a list of Item Numbers:
SELECT DISTINCT Name FROM TableName WHERE ItemNumber IN (...)
What I was trying to do is the following, but I am not exactly sure what is wrong:
WITH ProductLines (ItemNumber, ItemName, ItemValue)
AS
(
SELECT ItemNumber, Name, Value FROM ProductItems WHERE ItemNumber IN (...)
)
SELECT * FROM ProductLines -- Don't know the column names
PIVOT
(
... -- Not sure what should come here
FOR ItemNumber IN (...)
)
Thanks a lot,
Aric Levin
Is it possible in the SSRS Report Designer to rotate a textbox to run vertically, or simply to rotate the text in a textbox ? I have only seen this done within axes lables of charts, but not text boxes.
Thanks in advance,
Kenny
I have the following table:
Policy Sequence LossDate Description Amt
123 1 9-1-2012 property 100
123 2 10-1-2012 property 200
345 1 9-1-2012 property 100
345 2 10-1-2012 property 100
678 1 9-1-2012 property 100
I want to select the data as follows:
Policy LossDate1 Description1 Amt1 LossDate2 Description2 Amt2
123 9-1-2012 property 100 10-1-2012 property 200
345 9-1-2012 property 100 10-1-2012 property 100
678 9-1-2012 property 100 NULL NULL NULL
Is there a way to do this using T-SQL?
The max sequence number can vary, so far the max has been 12, but may be higher in the future.
I'm using the SQL indicated below:
SELECT
DISTINCT C.Field1 As 'Group',
A.Field2 As 'Security Object'
E.Field3 As 'User'
FROM TableA AS A
[code]...
However I'm having difficulties concatenating the user field in the horizontal form indicated.
Is there a way I can frame the querry for the following scenario??
column1
--------
item1
item2
item3
...
..
Querry: Select datediff(month,item1,item2) and next for item2 and item3...
Thanks
Hello. I know, you think I'm totally clueless, and you're right. SQL is the most confusing thing for me but I must learn it.
So, I am running a query to find out the name of the person who sold the most stoves with the least color purchased. I have ran that query and it works . My problem is that I have to add to that query another column that counts the number of stoves sold, instead of having them displayed one by one. My query is as follows:
SELECT EMPLOYEE.Name,STOVE.Color FROM INV_LINE_ITEM, STOVE, EMPLOYEE, INVOICE
WHERE INV_LINE_ITEM.FK_Stovenbr=STOVE.SerialNumber
AND INV_LINE_ITEM.FK_InvoiceNbr=INVOICE.InvoiceNbr
AND INVOICE.FK_EmpID=EMPLOYEE.EmpID
AND STOVE.Color IN (SELECT CAST(MIN(Color) AS CHAR(5)) 'Min Color' FROM STOVE)
AND EMPLOYEE.Name IN (Select CAST(MAX(Name) AS CHAR(15)) 'Employee Name' FROM EMPLOYEE)
ORDER BY EMPLOYEE.Name, STOVE.Color
Thank you
I have a single table and I want to check for the duplicates. On the bases of two column.
Namley HiNum, Procode.
so if there are duplicates I want to print out those records
How I can do that in a script.
I tried the following codes but I am getting an error. how I can fix it. Or this is completly wrong?
.
Select * from Claims Where HiNum in (Select HiNum,Procode,Count(*) as NumberOfRows
From Claims
Group by HiNumber, Procode
Having Count(*) > 1)
Hello
Can anyone give me the code to insert date from textbox to database(SQL Server 2000). The date fromat in SQL is dd-mm-yyyy.
Rathish
Hi! I 'd like to update the database..I 'd like to update the same field, the first update would set all to 'No' and the second update woyuld set specific records to 'Yes':
1) "Update tblDept SET IsTop ='No'
2) "Update tblDept SET IsTop = 'Yes' WHERE id = 200 "
Cheers!
Hi.
I know this querry:
"SELECT TOP 10 * FROM MyTable ORDERBY ..."
will give the top 10 rows.
But how can I build a querry that can get the rows from 40-50 (ie).
Thanks.
I have two tables linked with the colunm name systemId and I need to get all the systems responding to the condition (t1.software & 0000000001) = 1 and if they have any contacts I would like to see them.
Here is what I have for the moment however my querry do not return the system info if no contact exist and that is wrong.
select customers.customerId,customers.systemId,customers.country
from customers,contacts
where (customers.software & 0000000001) = 1
and customers.SystemId = contacts.SystemId
order by customerid
Systems
-SystemId
-CustomerId
-Name
...
Contacts
-ContactId
-SystemId
-Name
-Tel
...
I have created a small querry and for some reason my container (datalist) is not reconizing the company name This is also the first time that i have created a querry with two select statements in the sproc.... Does it make a difference if there is two select statements in a querry?? When populating a datalist?Not sure if i need to seperate the two statements some kind of way..
Is this ok to use with datalist? Erik.. ALTER PROCEDURE Get_Information_For_Datalist_Global_ @IDProduct AS INT, @IDCompany AS INT AS SELECT Product.ProductName, Product.ProductID,Product.ProductImage, Product.ProductDescription, SprocsTable.* FROM Product INNER JOIN SprocsTable ON Product.ProductID = SprocsTable.ProductID WHERE Product.ProductID = @IDProduct SELECT Company.CompanyID, Company.CompanyName FROM COMPANY WHERE COMPANY.COMPANYID = @IDCompany
is there a way to get the time that it takes a querry to run like down to the millsecond
View 2 Replies View Relatedhi.
i want to have a text box and command button. i will be entering the clients id in the text box and press the command button to search the clients record. this will be search query. i have done that previously in vb6. but dont know what query to write in vb08. Any help. thks.
There are 3 servers in our group which the Local Enterprise Manager Tool is giving us an error when we try to view local DB table data by right-clicking on the table and selecting return all rows... we get this error I thought this was a permissions error but as far as I know we haven't played with the permissions. This seems to be a common ailment here... does anyone have a fix for the EM tool.
An unexpected error happened during this operation.
[Query] - Query Designer encountered a Query error:
Unspecified error
I have two database on same server. I want write a querry, witch qering the data from 1st database, than create a new table on the 2nd database.
But the in clause after the into clause permanently generate error.
Here is the query€™s little part:
Select €¦..
into Backup in €™Test.mdb€™ from €¦
I try wrote other ways
in €™Test€™
in €™dbo.Test€™
in dbo.Test
but none of them work
its only work, when i not want pass for the second database
How can i pass the result for the 2nd Database
Hi,How to run a DTS from query analyzer using some t-sql commands??? Is it possible?? What is the command to run a DTS from QA???and What are the possible ways of running a DTS?? from how many types we can execute a DTS like 2 of it i know from EM directly and from the help of Schedule jobs.
View 1 Replies View RelatedDear all,
I have 2 SQL store procedure which are suppose to return similar number of data.
For an unknown reason one of the procedure is returning lasse data than the other.
in order to dig out the reason for that I need to compare the two set of data return by both procedure.
one by one is a huge woek has I have more than 1000 records.
So my question is that what is the easy way to extract data which has been forget or miss ?
For example
my procA return 500 rows
my procB return 400 rows
I would like to identify the 100 records which are in ProcA results but not in ProcB results
In other words extr^ct the difference between A and B
thnaks for your help
serge
Hello,
In SQL if we want to edit a row in a table then we have two ways to do the same,
1. Execute a command to Update the records in sql through querry analyzer.
2. Go to enterprise manager and then open the table and update a new row.
But can't we do the editing in the querry analyzer is there any way to do this.
That means i select all the records from my table using the following querry.
Select * from MyTable
and then performs editing in the querry analyzer without executing any update command and without using the Enterprise manager.
Can we do this????????
Bye and TC
hi.
i have created a database with a table called customer. hav a field which displays the date. how can i add a query on the date picker so that when i choose a date on the calendar i can view the customers details. in other display the record by choosing a particular date.
thx.
i lost my laptop driver's cd,right now i am using windows XP professional.and laptop is of compaq v3000.
so from where i get my laptops driver,can you help me out .?
Hello,
Need a bit of help here. In one table i have my production data on some wheels. Each time the wheel is touched, it gets smaller. Then in another table I have the primary data of that wheel, ie price vendor, make model and scrap diameter.
What I'd like to figure out is, In one month, what was the wheel size to start off, what is the end size to give me a total size used during that month. If i could get that, then I think I would be able to figure out what the price cost for useage of that wheel was for the month.
Any help?
Thanks Brian
hello!
can somebody tell me how i can redirect the result of my
select statement to a file.
thank's