Transact SQL :: Convert Non Fixed Rows To Non Fixed Columns Dynamically?
Oct 5, 2015
I have a table with 3 columns (ID Int , Name Varchar(25), Course Varchar(20))
My source data looks like below
ID     Name       Course
1Â Â Â Â Â Â Â AÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Java
1Â Â Â Â Â Â Â AÂ Â Â Â Â Â Â Â Â Â Â Â Â Â C++
2Â Â Â Â Â Â Â BÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Java
2Â Â Â Â Â Â Â BÂ Â Â Â Â Â Â Â Â Â Â Â Â Â SQL Server
2Â Â Â Â Â Â Â BÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â .Net
2Â Â Â Â Â Â Â BÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â SAP
3Â Â Â Â Â Â Â CÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Oracle
My Output should look like below...
ID     Name      Course(1)    Course(2)        Course(3)    Course(4) Â
1       A                Java           C++
2       B                Java           SQL Server .Net            SAP
3Â Â Â Â Â Â Â CÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Oracle
Basically need t-sql to Convert non fixed rows to non fixed columns...
Rule: IF each ID and Name have more than 1 course then show it in new columns as course(1) course(2)..Course(n)
Create SQL:
Create table Sample (ID Int null , Name Varchar(25) null, Course Varchar(20) null)
Insert SQL:
INSERT Sample (ID, Name, Course)
         VALUES (1,'A','Java'),
                (1,'A','C++'),
                (2,'B','Java'),
                (2,'B','SQL Server'),
                (2,'B','.Net'),
                (2,'B','SAP'),
                (3,'C','Oracle')
View 12 Replies
ADVERTISEMENT
Jun 5, 2015
I need to generate a csv file from another csv file, seems to be simple but let's go the trick thing:
Needs to have maximum 1000 lines, if I reach to this, I need to create another csv and fill that new one.
Exemplifying:
I have a csv file called fileA and this has 2000 lines and another csv called fileB with 1500 lines.
I need to loop a folder and get the fileA, create an output called FileAOutput and start to fill that, if I reach to 1000 lines, I need to create a FileAOutput_2 and fill the other 1000 lines...so I'll go to fileB and do the same thing, but in the second case, I'll have 500 lines in the second output.
View 5 Replies
View Related
Jan 7, 2008
Hi,
I need to count and display the number of records which have GradeTitle="SHO". I'm only starting to use BI development studio and all attempts at using the built in aggregate functions have failed.
Also, the report I wish to create has a fixed number of columns and a fixed number of rows as the info being displayed is really only counting values in the DB. I tried using Table but multiple rows were created.
I'd appreciate if anyone could point me in the right direction, as searching this forum turned out to be pretty fruitless for me.
Thanks in advance,
John
View 16 Replies
View Related
Jul 13, 2007
Hi
I have a dataset with 2 columns, a rownumber and a servername - eg
rownumber servername
1 server1
2 server2
....
15 server15
I want to display the servernames in a report so that you get 3 columns - eg
server1 | server2 | server3
server4 | server5 | server6
...
server13 | server14 | server15
I have tried using multiple tables and lists and filtering the data on each one but this then makes formating very hard - i either end up with a huge gap between columns or the columns overlap
I have also tried using a matrix control but cant find a way to do this.
Does anybody know an easy way to do this? The data comes from sql 2005 so i can use a pivot clause on the dataset if somebody knows a way to do it this way. The reporting service is also RS2005
Thanks
Anthony
View 1 Replies
View Related
Sep 14, 2007
I would like to convert a number into fixed format string. Say for example if I have number 5, I would like to show it as four charactered string:
0005.
In case if I have 33, then I would like to have a result like '0033'. Please let me know the string functions with which I can acheive this.
View 5 Replies
View Related
Aug 24, 2007
Hi, I have been trying to use the Fixedheader property on the left two columns of a table report. In Preview it works beautifully. After Deploy, the fixed columns somehow get resized to make the rowheight bigger but the rest of the table stays the same. The rows no long match when scrolling and you get lost of which row goes where. Is this a 'feature' of Reporting Services or am I doing something wrong???
Thanks, RS Challenged
View 4 Replies
View Related
Jun 14, 2004
A table has a column of int type. I need to select a fixed number of rows for each value. For example, if data in that column (c) are 5, 6, 7, and the number I want to select is 2, then I need 2 rows from c=5, 2 from c=6, and 2 from c=7. How to write that query? Any idea?
Thanks.
View 6 Replies
View Related
Jun 14, 2007
Is it possible to display only a certain number of columns in a matrix, say the first 6 and then hide the rest? That is, does the matrix allow to somehow control how many columns can be displayed from a column group and hide the remaining columns (I need this to limit the number of columns a user is able to see so that the matrix width does not get infinitely long).
In other words.....
I need to display the subtotals for all dynamically generated columns but display only first 6 columns. This way I can avoid having to display 50 columns and not have user scroll to so far right and keep the page width within reasonable limits. Hope I have made it clear.
Thanks.
View 3 Replies
View Related
May 7, 2008
I have a table with 30 rows. When the data is got from the DB these 30 rows may or may not be filled but they should be visualized. How can I do this? I mean if only 10 rows are filled with data the other 20 to be visible.
I want if cell content grows than the whole row to change its height. Is it possible?
View 2 Replies
View Related
Oct 8, 2015
How can I convert the following data
Create Table tbl_Customer_Bank_Details
(
[CustomerID] int,
[CustomerName] varchar(50),
[AccountType] varchar(50),
[BankAccountNo] varchar(50)
)
[Code] ...
into the following format
Create Table tbl_Customer_Bank_Details2
(
[CustomerID] int,
[CustomerName] varchar(50),
[AccountType] varchar(50),
[BankAccountNo1] varchar(50),
[Code] ....
I am looking at this [URL]
how to do this in SQL 2000.
View 16 Replies
View Related
Apr 24, 2015
i have a table with dob and test results , i am trying to pull the data from the table and converting rows columns , below is the table i am using . i used to pivot to do this .
create table #TEST_RESULTS
(ID INT,NAME VARCHAR(10),DOB DATETIME,DAYS_SINCE_BIRTH_TO_TEST INT,TEST_RESULTS INT )
INSERT INTO #TEST_RESULTS
VALUES(1,'A','2015-01-01' , 0 ,1)
,(1,'A','2015-01-01' , 0 ,1)
,(1,'A','2015-01-01' , 1 ,3)
,(1,'A','2015-01-01' , 2 ,6)
[code]...
View 9 Replies
View Related
Nov 7, 2006
I have a string with values value1,value2, value3, value(n) which I would like to append to my table.
In the second column of my table I have a parameter which stays the same, so I end up with (if the parameter value is "123456")
Column 1 | Column 2
123456 | Value1
123456 | Value2
123456 | Value3
I would like to set up a single SQL statement which will process this regardless of the number of values (therefore rows) desired.
Something like:
INSERT INTO dbo_tblUserLevelApplicationRequests ( Column1, Column2) select EmployeeNumberParam as EmployeeNumber, ((stringofvalues) as valuestring)
Is it possible to do this with a single SQL statement?
View 2 Replies
View Related
Oct 1, 2014
I have an issue where I have multiple rows of data and I need to reduce a dollar amount by a fixed maximum. I am going to throw some code in here to give a rudimentary idea of the data and what the final result should be.
declare @tbl table
(LineNum int,
Code varchar(2),
Amt money,
MaxAmt money
[Code] ....
I need to run an update so that the result of the following query:
select LineNum, Code, Amt, MaxAmt from
@tblLooks like this:
LineNum Code Amt MaxAmt
----------- ---- --------------------- ---------------------
1 AA 10.00 50.00
2 AA 20.00 50.00
3 AA 20.00 50.00
(3 row(s) affected)
I have tried cursors but got unexpected results or the MaxAmt always defaulted to the original even if I updated it. This seems like a simple problem but I have been banging my head against the wall for 2 days now. I've written some pretty complicated updates with less effort than this and I must have some mental block that is keeping me from figuring this out.
View 3 Replies
View Related
Aug 27, 2015
i have following table columns and i want to convert these all columns into row
SELECT [CASHINHAND]
,[CASHATBANK]
,[DEPOSITS]
,[ACCRECEVABLE]
,[SUNDRYDEBTORS]
,[LOANANDADVANCES]
[Code] ....
required output looks like
CASHINHAND 118950
CASHATBANK Â 200
DEPOSITS 3000
ACCRECEIVABLE
25000
View 3 Replies
View Related
Mar 4, 2015
I have this doubt and want to be sure if my thinking is correct.
Lets consider 2 tables one with Fixed length columns (char) and other table with Variable length columns (Varchar).
The table with fixed length column will always allocate same size within a Page however, table with variable length column will allocate actual length of data within a page.
I think that updates happening on table with fixed length columns will have more possibility of InPlace updates at least from data length perspective, however updates on table with variable length columns will have more split updates from data length perspective.
View 0 Replies
View Related
Jun 18, 2015
We are planning to develop weekly report in SSRS.For this we wants each day as column & some expenses[Numeric figure in row]we have dataset likeÂ
dayÂ
exp1
exp2
exp3
17/05/2015
120
150
650
[code]....
There are some other filters are there that i have applied in my report tablix property.
View 2 Replies
View Related
Jun 12, 2006
How do I delete columns in a fixed width column file connection object, after I've saved it I can't remove columns anymore?
View 1 Replies
View Related
Jun 17, 2015
Using the following tables and data---
CREATE TABLE tblRiskReviewHistory(RiskReviewID int, RiskReviewHistoryID int, Name nvarchar(20), Description nvarchar(50), Date date)
INSERT tblRiskReviewHistory(RiskReviewID, RiskReviewHistoryID, Name, Description, Date)
VALUES(1,1,'Customer A','Profile Assessment','01/01/2015'),
(1,2,'Customer B','Profile Assessment','02/20/2015')
[Code] ...
And currently outputs;
Name Description Date Question Answer
Customer A Profile Assessment 01/01/2015
How complex is the structure?
Customer A
Profile Assessment
01/01/2015
The total value of assets?
Less than GBP 1 million
Customer A
Profile Assessment
01/01/2015
The volume of transactions undertaken?
Low (-1 pmth)
[Code] ....
However, I would like it to output;
Name
Description
Date
How complex is the structure?
The total value of assets?
The volume of transactions undertaken?
How was the client introduced?
Where does the Customer reside?
[Code] ....
The number of questions are unknown for each RiskReviewID and they can be added to in the future.
View 7 Replies
View Related
Jun 3, 2015
I need to be able to export a data file as flat file (.txt) with fixed columns for use by Mainframe.
I will be uploaded this file using the Windows File Share Option
Render Format does not have .txt, but does have a data feed option. So I will try that.
But, I do not see an option for fixed column width.
View 7 Replies
View Related
May 29, 2006
Dear fellows,
I know that I think as sql2k programmer-dba yet but I can€™t avoid.
I€™ve got Flat File Connection Manager Editor dragged with a text file as €˜ragged right€™ format and CRLF as header row limiter. When from properties page and Columns option I€™m going to alter just a few colums I am not be able.
It seems that you must erase all of them in order to define one or two. And in the case you€™d have 50????
When I ran sql2k DTS designer did that without problems, alter columns again and again.
As far as I know it€™s a lose of flexibility, or not? Or is there any way for do that without deleting nothing else?
View 3 Replies
View Related
Sep 10, 2015
i want to break 2 by 2 rows in reportceiling(rownumber(nothing)/2).i used this expression in row group. URL....but i want to use this expression in matrix and that matirx is with in list . so i  am getting error . how to use rownumber in list.here i used list to break the page wise id
View 3 Replies
View Related
Apr 23, 2015
I need to create an output from a T-SQL query that picks a numeric variable and uses the print function to output with leading zeroes if it is less than three characters long when converted to string. Â For example if the variable is 12 the output should be 012 and if the variable is 3 the output should be 003.
Presently the syntax I am using is PRINT STR(@CLUSTER,3) .  But if @CLUSTER which is numeric is less than three characters I get spaces in front.
View 4 Replies
View Related
Jan 2, 2008
Hey All,
Similar to a previous post (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=244646&SiteID=1), I am trying to import data into a SQL Table.
I am trying to program a small application that will import product data obtained through suppliers via CD-ROM. One supplier in particular uses Fixed width colums, and data looks like this:
Example of Data
0124015Apple Crate 32.12
0124016Bananna Box 12.56
0124017Mango Carton 15.98
0124018Seedless Watermelon 42.98
My Table would then have:
ProductID as int
Name as text
Cost as money
How would I go about extracting the data with an XML Format file? I am stumbling over how to tell it where to start picking up data for a specific column.
Is there any way that I could trim the Name column (i.e.: "Mango Carton " --> "Mango Carton")?
I don't know if it makes any difference, but I've been calling SQL from my code by doing this:
Code in C# Form
SqlConnection SqlConnection = new SqlConnection(global::SQLClients.Properties.Settings.Default.ClientPhonebookConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO PhonebookTable(Name, PhoneNumber) VALUES('" + txtName.Text.ToString() + "', '" + txtPhoneNumber.Text.ToString() + "')";
cmd.Connection = SqlConnection;
SqlConnection.Open();
cmd.ExecuteNonQuery();
SqlConnection.Close();
RefreshData();
I am running Visual Studio C# Express 2005 and SQL Server Express 2005.
Thanks for your time,
Hayden.
View 1 Replies
View Related
Dec 6, 2013
I have like 100 columns and most of them work fine, but some will not work. I need to select the columns with correct width for fixed width flat file.
Here is typical SQL statment that works for most of them.
left(RTRIM(A.City) + Replicate(' ', 25) ,25) as [City]
The above one is not working, but many other works fine like the address. Why would it work for some, but not others?
It works fine if I use any char, but not space. i.e.
left(RTRIM(A.City) + Replicate('*', 25) ,25) as [City]
View 5 Replies
View Related
Apr 21, 2015
I have a table with single row like below
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Column0 | Column1 | Column2 | Column3 | Column4|
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Value0Â Â Â | Value1Â Â Â | Value2Â Â Â Â | Value3Â Â Â |Â Value4Â |
Am looking for a query to convert above table data to multiple rows having column name and its value in each row as shown below
_ _ _ _ _ _ _ _
Column0 | Value0
 _ _ _ _ _ _ _ _
Column1 | Value1
 _ _ _ _ _ _ _ _
Column2 | Value2
 _ _ _ _ _ _ _ _
Column3 | Value3
 _ _ _ _ _ _ _ _
Column4 | Value4
 _ _ _ _ _ _ _ _
View 6 Replies
View Related
Feb 13, 2007
Hi,
I am trying to create a program that transfers tables to flat files.
At this point in time, I have suceeded in created one that creates delimited files.
However, I am now trying to create fixed-width files as you can do with the SSIS designer, but programatically.
Is there a way to programatically determine the width of a column from the source table? I can not seem to find any kind of function or member that stores this information or allows me to retrieve it.
I know what I need to change in order to set a width for a column, but I just don't know how to find the width without just asking the user to provide one.
View 5 Replies
View Related
Dec 10, 2005
I've seen several posts that begin to address this problem, but havenot found a simple, elegant solution that will accomplish this goal.The important part of this solution is that it must be completelydynamic - I have over 40 different categories of devices, each withdifferent fields, and each search will return only one category. Ihave no knowledge of the number or datatype of these field namesbeforehand and must use the sp to dynamically create the table and thentranspose the data.Here is an exampleI have normalized data in this format (this is a simplification)deviceId fieldName fieldValue1 color red1 shape square1 weight(kg) 2.02 shape round2 weight(kg) 1.53 color blue3 shape oval3 weight(kg) 1.0I would like to convert this to the format: (note that it must handlenulls - deviceId 2)deviceId color shape weight(kg)1 red square 2.02 round 1.53 blue oval 1.0Anyone with any thoughts on how best to accomplish this?thanks,Matt
View 19 Replies
View Related
Nov 4, 2015
I want to change decimal precision dynamically without rounding value
For example
10.56788 value for 2 decimal precision is 10.56.
10.56788 value for 3 decimal precision is 10.567.
---CASE 1 without dynamic parameter---------
DECLARE @DECIMALVALUE AS tinyint
SELECT CONVERT(DECIMAL(10,2),500000.565356) As Amount
[Code] ....
I am getting error as follows......
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near '@DECIMALVALUE'
This decimal precision format value will vary company to company ...
View 7 Replies
View Related
May 1, 2006
Can someone from MS tell me if this has been fixed in SP1?
http://blogs.conchango.com/jamiethomson/archive/2005/10/11/2261.aspx
Thanks
Jamie
View 3 Replies
View Related
Dec 2, 2003
Hi all.
I'm trying to export some tables in fixed width format for a client that needs it this way. The first time I did this, using Import/Export in Enterprise Manager, integer fields were 12 chars long. However, when I saved this as a DTS and ran it again later, it made integers 4 chars in the text file (which matches the lengths of the datatypes you see in enterprise manager.)
Why is this difference there? What do I need to do differently? Also, is there a list of how wide each data type is when exported as fixed delimited text?
thanks,
Craig
View 2 Replies
View Related
Jan 22, 2005
Hello Friends
I am very glad to tell all u ppl that i ve got the solution to my problem at last
I ve just posted my problem(few mins back) in which i was getting problem with connecting to the ASP.NET Web application. I have made a new user on sql through SQL Enterprise Manager as <machinename>ASPNET, and my problem gets solved
sorry to bother u all
Regards
BSS
View 1 Replies
View Related
May 30, 2006
philippe writes "Hello ,
i am just starting with sql...
I have a table: Table_user
Inside a column user_no (integer)
with value like 35678 (about 8000 rows)
I would like to modifie all rows of this Table_user.user_no
with a value of 60 at the begining of each value.
For example : before 35678 will be 6035678
Its'a concatenation,but it's an integer value .
so do i need to convert tehm to varchar first
I will appreciate some tips...."
View 5 Replies
View Related
Aug 15, 2007
Hi everyone,
I'm trying to make a hierarchy in which some nodes are locked, preventing children nodes from being added.
The hierarchy table points to itself (the parent entry). I want to secure this from the DB side. Initially, no nodes have parents but can attach themselves to one.
I'd like my FK contraint to be like:
CONSTRAINT FK_hierarchy FOREIGN KEY (parent_id, 1) REFERENCES nde_recursion(hierarchy_id, allow_children)
This is so the parent_id can only be set if that entry allows children.
Here's my approach. Any better ideas? I feel like I'm adding an extra field (parent_allow) when I shouldn't.
CREATE TABLE hierarchy(
hierarchy_idINTIDENTITY(1,1) UNIQUE NOT NULL,
allow_childrenBITDEFAULT 1 NOT NULL,
parent_idINT,-- NULL is for root nodes
parent_allowBITDEFAULT 1 NOT NULL,
CONSTRAINT PK_hierarchy PRIMARY KEY (hierarchy_id, allow_children),
CONSTRAINT FK_hierarchy FOREIGN KEY (parent_id, parent_allow) REFERENCES nde_recursion(hierarchy_id, allow_children),
CONSTRAINT CK_hierarchy CHECK ((nde_status = 'Normal' AND parent_id IS NULL) OR (nde_status != 'Normal' AND parent_id IS NOT NULL)),
CONSTRAINT CK_hierarchy2 CHECK (parent_allow = 1)
)
View 5 Replies
View Related