Make A Horizontal Table Into A Vertical Table

Nov 19, 2004

Hi All,
Any assistance would be greatly appreciated.

I have a current table which I create on a regular basis from a text file with a layout similar to this:
TypePolicy #AmountRider 1 AmtRider 2 Amt
B1112H24.341212.34

This text file is brought into a staging table with each field (even the amount field) as a varchar (12). I then assign types in a later step in my DTS package.

What I need to do is stack the riders under each policy so for each policy where there is a rider, there is a new row for every rider.
So in the example I've given, there would be 2 additional rows for the original first row since there are two riders.
TypePolicy #Amount
B1112H24.34
R11112H12
R21112H12.34

I plan on doing this by first creating a table with just the Type, Policy #, and Amt fields, and then using a series of insert queries where I take the rider (if there is one) and append it onto the table.

However, I'm getting the following error message when I try:
Server: Msg 213, Level 16, State 4, Line 1
Insert Error: Column name or number of supplied values does not match table definition.

Basically, it wouldn't let me put an 'R1' in the Type column.
How can I get this to work!?!?

Thanks in advance for your help

View 6 Replies


ADVERTISEMENT

Make Tbl_SP From Vertical To Horizontal

Jul 7, 2004

Hi,

What I need is the following, a StoredProc that make a Vertical (normal table) into a Horizontal Table :
So From:
CustNo__Item

__1______1
__1______3
__1______4
__2______2
__2______3
__2______7

To:
CustNo___1__2___3___4___7

_1_______X______X___X
_2__________X___X_______X

Anny help would be verry appriciated

View 1 Replies View Related

Horizontal To Vertical Table

Jan 7, 2015

I have a table like this:

weight type factory1 factory2 factory3 factory4.... to factory 150

1kg goods 5.00 5.50 5.20 5.00...
2kg goods 6.00 6.20 6.15 6.30...
3kg goods 4.00 4.50 5.00 4.30...
...

and would like to extract data this way:

producer type weight price

factory1 goods 1kg 5.00
factory1 goods 2kg 6.00
factory1 goods 3kg 4.00
factory1.....
then

factory2 goods 1kg 5.50
factory2 goods 2kg 6.20
and so on for all factories.

I tried with UNPIVOT but it does not allow it (I'm using Navicat 8), saying "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near UNPIVOT...".

View 2 Replies View Related

Horizontal To Vertical Array?

Nov 29, 2012

I'm running SQL Server 2008 Standard.I need to create a query that has data from multiple columns (Columns 1-6 with coresponding Date started and Date Completed data) displayed vertically, but also has the column name the preeceeding column to identify it...along with other data (Record number, status).

Record Number, Status, Column Name, Date Started, DateCompleted
1, Open, Column 1, 1/1/2012, 2/1/2012,
2, Hold, Column 2, 1/3/2012, 3/1/2012,
1, Open, Column 3, 2/5/2012, 4/6/2012,
3, Closed, Column 4, 5/10/2012, 7/25/2012,
2, Hold, Column 5, 3/9/2012, 4/1/2012,
1, open, Column 6, 10/10/2012, 12/12/2012,

View 5 Replies View Related

How To Convert Vertical To Horizontal Row

Jun 13, 2008

id name
--- -----------------
236 SERVICE REQUEST
236 HARDWARE
236 Desktop
336 Loan

id name
-- ----------------------------
236 SERVICE REQUEST/ HARDWARE/ Desktop/Laptop/ Loan

View 5 Replies View Related

Sql For Results From Vertical To Horizontal

Mar 15, 2008

Hi all

I dont want to use functions or proceedures but with select itself I want to get the above mentioned result. Can somebody help


SURESH IYER

View 2 Replies View Related

Converting Vertical Data To Horizontal

May 25, 2006

I have a table as follows
opendate (datetime) callnumber (int) closed (bit)

I want to find how many calls were opened today and of those how many are closed

I have come up with the code below but again am looking for
1. a more elegant solution
2. a way to generalise this to show the same information for x number of days




create table #holdit1
(opencount int)

create table #holdit2
(closedcount int)

insert into #holdit1
SELECT count(*) as opencount
FROM [dbo].[problog]
WHERE datediff(dd, opendate, getdate()) = 0
AND closed = 0
group by closed

insert into #holdit2
SELECT count(*) as closedcount
FROM [dbo].[problog]
WHERE datediff(dd, opendate, getdate()) = 0
AND closed = 1
group by closed


select #holdit1.opencount AS CallsOpen, #holdit2.closedcount AS CallsClosed, #holdit1.opencount + #holdit2.closedcount AS AllCalls
from #holdit1 cross join #holdit2 #holdit2


DROP TABLE #holdit1
DROP TABLE #holdit2



this gives me
CallsOpen CallsClosed AllCalls
----------- ----------- -----------
1 3 4

View 4 Replies View Related

Append Vertical Row Result Into Horizontal

May 19, 2015

I want to append vertical row result into horizontal

CREATE  TABLE  #mable(mid INT, token nvarchar(16))
INSERT INTO #mable VALUES (0, 'foo')
INSERT INTO #mable VALUES(0, 'goo')
INSERT INTO #mable VALUES(1, 'hoo')
INSERT INTO #mable VALUES(1, 'moo')
Actual output

[code]....

View 14 Replies View Related

Challenge : Vertical View To Horizontal In A StorProc

Jul 9, 2004

From:
Cust | Qstion | Answer
_________________________________
1,1,Bike
1,4,Blue
1,6,No ensurance
2,1,Car
2,3,silver
2,9,ensurance
2,11,Yes


To the following
Cust______1______3______4______6______9______11
__________________________________________________ __________
1_______Bike___________Blue__No ENsur_________
2_______car____silver_________________Ens____Yes"

View 5 Replies View Related

Have Query Results Display Vertical Instead Of Horizontal?

Apr 15, 2015

I have a query that calculates sales by sales person, but it displays horizontally across my query window. Is their a way in SQL Server to have the data display vertically down the window instead?

This is my current query

Code:

Select
count(case when salesman Like 'Geo%' then id else null end) As [George]
,count(case when salesman Like 'Li%' then id else null end) As [Lisa]
,count(case when salesman Like 'Jor%' then id else null end) As [Jorge]
,count(case when salesman Like 'Ri%' then id else null end) As [Richard]
,count(case when salesman Like 'Geo%' then id else null end)+count(case when salesman Like 'Li%' then id else null end) As [Team 1 Sales]
,count(case when salesman Like 'Jor%' then id else null end)+count(case when salesman Like 'Ri%' then id else null end) As [Team 2 Sales]
from sales.southeastregion

Which of course shows the results as such

George --- Lisa --- Jorge --- Richard --- Team 1 --- Team 2
100 50 10 90 150 100

And I want the data to be displayed like

George - 100
Lista - 50
Jorge - 10
Richard - 90
Team 1 - 150
Team 2 - 100

This is SQL Server 2008 if that matters.

View 5 Replies View Related

T-SQL (SS2K8) :: Horizontal To Vertical Rows Conversion?

May 14, 2014

create table #temp1
(
col1 float,
col2 float,
col3 float,
clo4 float)
insert into #temp1 values (1.5, 1.6,1.7,1.8)
insert into #temp1 values (1.9, 1.0,1.2,1.8)

o/p should display as below is there a way we can do this with cte or some other option

col1 1.5 1.9
col2 1.6 1.0
col3 1.7 1.2
col4 1.8 1.8

View 1 Replies View Related

Horizontal Output Of Vertical Query With Cursors

Mar 31, 2008

TaskID PID task Milestone
83manasi task2
83manasi task3
83manasi task4


Above is the query of the result
I want to show this resultset horizontaly
for that I have to use the cursor such that
@M1=Where Milestone=1
@M2=Where Milestone=2
@M3=Where Milestone=3
and putting this into a temp table with its projectid and taskid.
Plz guide me that how to achiev this exactly
Swati

View 1 Replies View Related

How To Convert Data Horizontal To Vertical In Server

Jul 24, 2015

Month Discount
Expenses GST
<gs class="GINGER_SOFTWARE_mark" ginger_software_uiphraseguid="d14582be-eecd-4def-be7e-0cfe00b13c80" id="4279c12f-e03f-4b38-9fc8-eb1a991c25ac"><gs class="GINGER_SOFTWARE_mark" ginger_software_uiphraseguid="7f0da910-3775-4ee4-821e-1a0e7ee2ce0b"
id="92ce074f-ee0b-4794-839b-ee50c88d380c">ServiceCharge</gs></gs>

[Code] ....

View 2 Replies View Related

Textbox Rotation Or Display Horizontal Vs Vertical

Jun 20, 2006

Is it possible to align a text box to display text with rotation? For example can I display it rotated 90 degrees left so that it reads from the bottom towards the top of the page? All I can find is left/right alignment and top/middle/bottom alignment. I want to rotate the text.

Thanks.

View 37 Replies View Related

Textbox Rotation Or Display Horizontal Vs Vertical (and WRAPPING)

Mar 26, 2008



Hello I was very happy to have found the thread http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=491642&SiteID=1 that explained how to get the text to display Bottom-to-Top/Left-to-Right.

The solution was to setup a function that creates a bitmap the text to be displayed.
This works well and correctly displays the text image in HTML and PDF. (Excel, XML and CVS won't export backgroud images).

To extend the solution to wrap text it requires a few additional lines...




Code Snippet
Function LoadImage3(ByVal stText As String)

stText = stText.PadRight(10)
stText = stText.PadLeft(10)
Dim iMaxLength as Integer = 180
Dim iMaxWidth as Integer = 180
Dim f As Drawing.Font = New Drawing.Font("Arial",7, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point)
Dim bmpImage As New Drawing.Bitmap(1, 1)
Dim MyGraphics As Drawing.Graphics = Drawing.Graphics.FromImage(bmpImage)

Dim imageSize As Drawing.SizeF = MyGraphics.MeasureString(stText, f)
Dim i As New System.Drawing.Bitmap(iMaxWidth, iMaxLength)
Dim g As Drawing.Graphics = Drawing.Graphics.FromImage(i)
Dim rectF1 As New Drawing.Rectangle(-(iMaxWidth/2),-(iMaxLength/2),iMaxWidth,iMaxLength )
g.FillRectangle(Drawing.Brushes.White, 0, 0, i.Width, i.Height)
g.TranslateTransform((iMaxWidth/2), (iMaxLength/2) )
g.RotateTransform(270.0F) 'flip the image 270 degrees

g.DrawString(stText, f,Drawing.Brushes.Black, rectF1)
g.DrawRectangle(New Drawing.Pen(Drawing.Color.White, 1), rectF1)
g.Flush()
Dim stream As IO.MemoryStream = New IO.MemoryStream
Dim bitmapBytes As Byte()
i.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg) 'Create bitmap
bitmapBytes = stream.ToArray
stream.Close()
i.Dispose()
Return bitmapBytes


End Function







Items highlighted in yellow reflect changes made to orignal solution.

Hope this helps!!

View 1 Replies View Related

How To Convert Verical Table To Horizontal Table?

Mar 4, 2008

I’ve a vertical table as follows: CMDATA

IDFormIDRecordCountFieldNameValue
15251204 Name John
25881204 OrganizationGE
35251257 Name Peter
45881257 OrganizationIntel
55251272 Name Rita

And a horizontal table as follows: CMFORM

IDFormIDRecordCount
15251204
25251257
35251272
45881204
55881257

Where
CMDATA.FormID = CMFORM.FormID and
CMDATA.RecordCount = CMFORM.RecordCount

Now I want select records as follows:

RecordCountNameOrganization
1204 JohnGE
1257 Peter Intel
1272 RitaNULL

I’ve written following query for that but it works properly only if all the record count has similar fieldnames.

SELECTCMCF.RecordCount,
CMD1.VALUE AS Name,
CMD2.VALUE AS Organization
FROMCMDATA CMD1
JOIN CMFORMS CMCF ON CMD1.FORMID = CMCF.FORMID AND CMD1.RECORDCOUNT = CMCF.RECORDCOUNT
JOIN CMDATA CMD2 ON CMD2.FORMID = CMCF.FORMID AND CMD2.RECORDCOUNT = CMCF.RECORDCOUNT
WHERECMD1.FIELDNAME = 'Name'
AND CMD2.FIELDNAME = 'Organization'
AND CMCF.RecordCount in(1204,1257,1272)

Is there any other way to handle this?

View 3 Replies View Related

How To Convert Verical Table Into Horizontal Table

Mar 4, 2008

I’ve a vertical table as follows: CMDATA

IDFormIDRecordCountFieldNameValue
15251204 Name John
25881204 Organization GE
35251257 Name Peter
45881257 OrganizationIntel
55251272 Name Rita

And a horizontal table as follows: CMFORM

IDFormIDRecordCount
15251204
25251257
35251272
45881204
55881257

Where
CMDATA.FormID = CMFORM.FormID and
CMDATA.RecordCount = CMFORM.Record Count

Now I want select records as follows:

RecordCountNameOrganization
1204 JohnGE
1257 PeterIntel
1272 RitaNULL

I’ve written following query for that but it works properly only if all the record count has similar fieldnames.

SELECTCMCF.RecordCount,
CMD1.VALUE AS Name,
CMD2.VALUE AS Organization
FROMCMDATA CMD1
JOIN CMFORMS CMCF ON CMD1.FORMID = CMCF.FORMID AND CMD1.RECORDCount = CMCF.RECORDCount
JOIN CMDATA CMD2 ON CMD2.FORMID = CMCF.FORMID AND CMD2.RECORDCount = CMCF.RECORDCount
WHERECMD1.FIELDNAME = 'Name'
AND CMD2.FIELDNAME = 'Organization'
AND CMCF.RecordCount in(1204,1257,1272)

Is there any other way to handle this?

View 3 Replies View Related

Using A Normalized (vertical) Table

Sep 24, 2007

I'm working on a couple projects and I've recently been trying to make everything fully normalized so updates are easier and I'm just wondering if there's a standard way to query and update normalized tables.
For example:
If I have table People with columns ID, FirstName, LastName, Height, Weight, ShoeSize, I can normalize that into two tables. Table People has ID, FirstName and LastName. Table PeopleDetails has PeopleID (FK), Property and Value. That way i can add more properties later right at the presentation layer if I like. Essentially I moved the data from being horizontal to being vertical.
But doing a simple search for people means I have to search the details table and return a LOT more records (one each for Height, Weight and ShoeSize) not to mention any more details I might add later. With a lot of details, it seems like your performance would take a big hit and your code would get really complicated as your looping through a vertical dataset to find the properties you want. Or is there some other standard way of doing that?
I'm just hoping that someone else has solved these problems and there's a standard set of functions out there for selecting and updating this kind of DB structure. Anyone?

View 6 Replies View Related

When To Make A Vertical Partition In Data Warehous

Jun 5, 2008

Hi All,

I am trying to understand, when would I do a vertical partition in a Dimensional Data Warehouse ? What are the things I need to consider, before I take the decision?

Necessity is the mother of all inventions!

View 7 Replies View Related

Could Anybody Tell Me How To Convert Vertical Data Into Horizontal Data?

Sep 2, 2005

Could anybody tell me how to convert vertical data into horizontal data?I have a one-to-many relationship in sql server 2KProduct, ProductAccessory, one Product has many ProductAccessories.My Table design is like this:Table Product{   ProdId int,   ProdNameId int,   ....}Table ProductAccessory{   ProdId int,   AccNameId int,   AccUnitId int,   ....}Because one Production has at most 4 ProductAccessoryI want to use a SELECT statement OR function to return ProdId, ProdNameId, AccNameId1, AccUnitId1, AccNameId2, AccUnitId2, AccNameId3, AccUnitId3, ....Any help will be appreciated! Thanks a lotJoseph

View 3 Replies View Related

Horizontal Partition Of A Huge Table

Jul 1, 2005

Hi,

I have a table with 52 million rows which resides on Primary file group in my database. Because of huge number of rows the performance has gone very down and I would like to break the table into parts.

Can anyone suggest me the steps for doing the same and the number of parts that should be made. It is named as Account_Transactions and contains information of Policies in an insurance database.

Rajat

View 2 Replies View Related

Vertical Partition Of Table With TEXT Data Type

Feb 11, 2008



Hi
Column with TEXT datatype is not stored in the same data row any way. I am wondering if there is any performance gain to put it in a seperate table. Thanks

View 4 Replies View Related

Reporting Services :: Horizontal Table And Page Break

Dec 2, 2015

I have a dataset with 2 fields : code and value. I have a parameter that will give me the data to insert into the table I want to make. The number of rows is not fixed, so I couldn't create, for example, a table with a fixed number of rows.

I want to create some kind of table that will allow me to have cells that look like this :  "code" : "value" and have 3 of them (like 3 columns) before I switch to the next line (row). 

Just to make it clear, I'm not using any SQL requests here, data comes from XML.

It should look like this :

code1 : value1   code2 : value2   code3 : value3
code4 : value4   code5 : value5   code6 : value6
code7 : value7

and it'll go like this until I've used all the data.

View 5 Replies View Related

Naming A New Table From A Make Table Query

Mar 25, 2004

I want to use a Make Table Query to generate a new read-only Table. This I can do but my problem is that I want to be able to name the new Table containing only the records from a calendar year; e.y. Rents2001 and the next year another new table would be created and called Rents2002 and next year Rents2003 ...............

I require the Table to be generated yearly. I know I could do this in other ways but I really require the Table as once I have it I will be doing other things with it to give the final report.

Any suggestions how I can generate the Table with the YEAR being in the Table Name as part of running the Make Table Query? Thanks

View 4 Replies View Related

Procedure Or Query To Make A Comma-separated String From One Table And Update Another Table's Field With This String.

Feb 13, 2006

We have the following two tables :

Link  ( GroupID int , MemberID int )
Member ( MemberID int , MemberName varchar(50), GroupID varchar(255) )

The Link table contains the records showing which Member is in which Group. One particular Member can be in
multiple Groups and also a particular Group may have multiple Members.

The Member table contains the Member's ID, Member's Name, and a Group ID field (that will contains comma-separated
Groups ID, showing in which Groups the particular Member is in).

We have the Link table ready, and the Member table' with first two fields is also ready. What we have to do now is to
fill the GroupID field of the Member table, from the Link Table.

For instance,

Read all the GroupID field from the Link table against a MemberID, make a comma-separated string of the GroupID,
then update the GroupID field of the corresponding Member in the Member table.

Please help me with a sql query or procedures that will do this job. I am using SQL SERVER 2000.

View 1 Replies View Related

Make A Backup Of A Table

Apr 27, 2007

What is the best way (short of backing up the entire DB) to make a copy of a Table so that It can be easily restored. We have a table that we want to make some serious changes to, but I want to make sure I can restore if if I need to (if the changes don't work)

View 10 Replies View Related

Make Table Unreadable

Sep 19, 2007

Hi all, I have a problem. I need a query that blocks table and makes it unreadable. I decided to use WAITFOR to long blocking.


BEGIN TRAN myStopReadTrans

USE MyDatabase
SELECT * From dbo.AB with(readpast,updlock)

WAITFOR DELAY '1:00:00'

COMMIT



USE MyDatabase
Select name from dbo.Clients

View 10 Replies View Related

How To Make Table Name Dynamic

Dec 31, 2007



Hi,

In my application i need to access mutiple table. I'm writing a stored procedure
in which i need to access tables such as TB01,TB02 .. Basically TBFY
where FY is parameter.

I tried for OPENQUERY, but that needs me to add a linked server, which i don't
think is a good idea.

Can anyone suggest on how can i do so?


I'm using SqlServer2000.

Thanks.

View 6 Replies View Related

How To Make Table Name Dynamic

Nov 19, 2007

Hi,

I have a requirement where i need to build the table name dynamically in the following queries.


declare @REF_DATA_TYPE nvarchar(20)

set @REF_DATA_TYPE='COUNTRY'



these are 4 cases where i need to use the table name dynamically

1. IF exists(select 1 from 'MD_REF_'+@REF_DATA_TYPE where code=@code_T)

2. Update 'MD_TB_REF_'+@REF_DATA_TYPE

3. from @ACTUAL_DATA p join 'MD_REF_'+@REF_DATA_TYPE T on T.code=P.code

4. INSERT INTO 'MD_REF_'+@REF_DATA_TYPE(Code,[Name],Description)


But i am getting error when i do this.

Please let me know what to do to solve this

Thanks in advance

View 5 Replies View Related

Execute A Vb.net File When I Make Some Changes In A Table

Mar 7, 2007

I want to execute a vb.net 
file

When I make some changes in a table.

 

How can I handle this situation?

 I am using sql server
2005 express edition sujith 

 

View 1 Replies View Related

How To Make Or Add A Table With A Field With Default Value

Nov 7, 2007

 I am doing a shopping basket type demo.I have difficulties going from table with fields like (Name,ProductCode) to table(Name, ProductCode, NumberOfItems). One way could be adding just Name and ProductCode fields and let NumberOfItems come automatically. It could have some common value like 1.  How should I do this with VB. 

View 1 Replies View Related

How Can I Make A Script Out Of A Table Data ?

Aug 30, 2003

Hello,

I want to take a table (SQL server) and show all it's data in a form of INSERT... (text file)
so that I can show it on a web-page and just paste the INSERT text into a MyTableData.sql
and then I can just run this script on the Query analyzer and fill my table with data

I need it so I can backup my DATA both in English and other languages...
(a replacement for the DTS packages that gives me hard time with the LOCALE / UNICODE translation)


did anyone already made such program ?
where can I find something like this ?

View 3 Replies View Related

How To Make Table Relations Using Query.

Mar 18, 2004

.

Hi,

How can I make relations between two tables using query? Tables are already there with data.

Regards

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved