Adding A Column On Output

Sep 27, 2005

I have two queries I would like to combine the output on. they are as follows:

Select substring(WrkSta.[Name],1,2) 'Location'
,count (aexe.ReturnCode) as '# Patched'
from WrkSta, AeXEvt_AeX_SWD_Execution aexe
where WrkSta.WrkStaId=aexe.WrkStaId
and (WrkSta.[Name] like 'ES%' or WrkSta.[Name]like 'EM%' or WrkSta.[Name] like 'EP%'
or WrkSta.[Name]like 'AB%' or WrkSta.[Name] like 'SU-NP%'
or WrkSta.[Name] like 'ET%')
and (aexe.returncode='0' or
aexe.returncode ='3010')
and aexe.AdvertisementName like 'MS05-035-043%'
group by substring (WrkSta.[Name], 1,2)

---
Returns :
Location # Patched
EP 102
ES 1986
ET 19
AB 174
SU 6
EM 506

and the second one:

Select substring(WrkSta.[Name],1,2) 'Location'
,count (coll.WrkStaId ) as '# Workstation'
from WrkSta join AeXNSCollectionMembership coll on WrkSta.WrkStaId=Coll.WrkStaId
where coll.CollectionGuid = '38F5DAFC-E09D-49A5-A0FD-370983CA7596'
and (WrkSta.[Name] like 'ES%' or WrkSta.[Name]like 'EM%' or WrkSta.[Name] like 'EP%'
or WrkSta.[Name]like 'AB%' or WrkSta.[Name] like 'SU-NP%'
or WrkSta.[Name] like 'ET%')
group by substring (WrkSta.[Name], 1,2)

---
returns:

Location # Workstations
EP 178
ES 2299
ET 24
AB 215
SU 13
EM 582


What I need is :

Location # Workstations # Patched
EP 178 102
EI 2299 1986
ET 24 19
AB 215 174
SU 13 6
EM 582 582

No mater how I try to do a join to do this in a single query I end up with what looks like a cross-join and # workstations and # Patched jump to huge numbers. I obviously am having a problem understanding how to set up the select statements so that I can do this in one query or am I following the wrong direction and should be trying something else?
Once again I appreciate your help in advance....

View 1 Replies


ADVERTISEMENT

Using Output From A Stored Procedure As An Output Column In The OLE DB Command Transformation

Dec 8, 2006

I am working on an OLAP modeled database.

I have a Lookup Transformation that matches the natural key of a dimension member and returns the dimension key for that member (surrogate key pipeline stuff).

I am using an OLE DB Command as the Error flow of the Lookup Transformation to insert an "Inferred Member" (new row) into a dimension table if the Lookup fails.

The OLE DB Command calls a stored procedure (dbo.InsertNewDimensionMember) that inserts the new member and returns the key of the new member (using scope_identity) as an output.

What is the syntax in the SQL Command line of the OLE DB Command Transformation to set the output of the stored procedure as an Output Column?

I know that I can 1) add a second Lookup with "Enable memory restriction" on (no caching) in the Success data flow after the OLE DB Command, 2) find the newly inserted member, and 3) Union both Lookup results together, but this is a large dimension table (several million rows) and searching for the newly inserted dimension member seems excessive, especially since I have the ID I want returned as output from the stored procedure that inserted it.

Thanks in advance for any assistance you can provide.

View 9 Replies View Related

Adding B Record To Output File

Apr 9, 2014

I'm not sure if I can explain this properly, but I'll try. I need to create an output file with a detailed record. I've been able to create a query that will give me the format and fields of what I need. However, the file layout calls for an additional "B" record if certain criteria is met in the detail immediately following the detail record. For example, if the PaymentMethodID = 10, then I need to add a "B" record that displays the PayeeName. I'm not sure if this would be a separate Select or a Union or maybe an Insert? All of our current layout are just Detail records and a Control Record.

Here is my current Select for the Detail:

SELECT DISTINCT
CONVERT(CHAR(10), ba.AccountNumber)
+ (REPLICATE('0', 10 - LEN(p.CheckNumber)) + CONVERT(VARCHAR(10), p.CheckNumber)) + REPLACE(CONVERT(VARCHAR(6), p.CheckDate, 1), '/', '')

[Code] ....

What I would need to add a separate B record?

View 1 Replies View Related

Adding Spaces To Query Output -- Really Stuck!!

May 10, 2001

I want to add 3 spaces at the end of each row for the result of a query.

The initial query being output to a text file (USING DTS) is:

select colA, colB =
CONVERT( CHAR(15), TableX.ColB )
from TableX
------------------------------------------------------------------------

BUT WHEN I EXPORT THE FOLLOWING (USING DTS), I GET THE SAME RESULTS

select colA, colB =
CONVERT( CHAR(18), TableX.ColB )+char(32)+char(32)+char(32) -- ' '
from TableX

Replacing the char(32) with ' ' (3 spaces in quotes) doesn't help.

Any ideas of how to append the 3 spaces after each record when exporting to
a text file using DTS??

Thanks

View 2 Replies View Related

Adding Error Output To Custom Source Component

Dec 6, 2007

Hi all,
I saw a couple of other posts here on this topic, but none quite got to my issue.
I'm trying to add error output to a custom source component (not a script, a custom component). The samples all seem to deal with transform components, and my issues seem to be unique to source components.

I have the following code related to error handling ...

Public Overloads Overrides Sub ProvideComponentProperties()

...

Dim output As IDTSOutput90 = ComponentMetaData.OutputCollection.New

output.Name = OUTPUTCOLUMNNAME


output.ExternalMetadataColumnCollection.IsUsed = True

ComponentMetaData.UsesDispositions = True

output.ErrorRowDisposition = DTSRowDisposition.RD_NotUsed

output.ErrorOrTruncationOperation = "Something got truncated or blew up"

Dim errorOutput As IDTSOutput90 = ComponentMetaData.OutputCollection.New

errorOutput.Name = ERRORCOLUMNNAME

errorOutput.IsErrorOut = True

...
End Sub


Public Overloads Overrides Sub ReinitializeMetaData()


Dim output As IDTSOutput90 = ComponentMetaData.OutputCollection(OUTPUTCOLUMNNAME)

Dim outColumn As IDTSOutputColumn90 = output.OutputColumnCollection.New


outColumn.Name = strName

outColumn.SetDataTypeProperties(DataType.DT_I4, 0, 0, 0, 0)



Dim metadataColumn As IDTSExternalMetadataColumn90 = output.ExternalMetadataColumnCollection.New


metadataColumn.Name = outColumn.Name

metadataColumn.DataType = outColumn.DataType

metadataColumn.Precision = outColumn.Precision

metadataColumn.Length = outColumn.Length

metadataColumn.Scale = outColumn.Scale

metadataColumn.CodePage = outColumn.CodePage

outColumn.ExternalMetadataColumnID = metadataColumn.ID


outColumn.ErrorRowDisposition = DTSRowDisposition.RD_NotUsed

outColumn.ErrorOrTruncationOperation = "Something Truncated!"

outColumn.TruncationRowDisposition = DTSRowDisposition.RD_NotUsed

Dim errorOutput As IDTSOutput90 = ComponentMetaData.OutputCollection(ERRORCOLUMNNAME)

Dim errorColumn As IDTSOutputColumn90 = errorOutput.OutputColumnCollection.New

errorColumn.Name = outColumn.Name

errorColumn.SetDataTypeProperties(DataType.DT_I4, 0, 0, 0, 0)
...
End Sub

The confusions I have are:
a) the stock advanced properties editor (I haven't provided a custom one) doesn't seem to "realize" that I have an error output, so provides no method to configure. I am believing it would need to know which Output columns can have their error/truncation redirected. I'd have thought setting ErrorRowDisposition on my output column would have been enough to trigger this ??
b) since I don't have any means of configuring, not surprisingly, when I try to connect my error output, designer complains that, "Ths error output cannot receive any error rows. This occurs for several reasons: Input columns or output columns are not yet defined. Error handling is not supported by the component. Error handling is not configured for the component."
c) UsesDispoistions would seem to be appropriate only for a transform component

Thanks for reading, and appreciate any help or pointers.
Bill

View 5 Replies View Related

Output To Fixed Width Flat File Not Adding Line Breaks

May 19, 2008

Hi All,

I have a simple SSIS package that runs a query on the db and outputs a fixed width flat file. I have all my column widths defined and in the connection manager i can preview the output. Everything looks great. All the fields fall where they should and each record is on it's own line.

When i run the SSIS program and then go open my text file with a text editor the ouput is all on the same line. I have tried changing my file format from fixed width to ragging right and adding a row delimiter but that doesn't work either. I feel like i'm missing something small here. It could even be an issue w/ my text editor (although i've tried to open the text file in multiple editors). In the flat file connection manager I have my file defined to be 187 characters long, So figure every 187 characters it should output a new line (it should add the carraige return right?).

Has anyone encountered an issue like this?


Any help would be much appreciated.

View 4 Replies View Related

Adding Column Where Adding Year To Date In Date Format

Aug 6, 2013

What is the syntax for adding a column where you are adding a year to a date in a date format? For example adding a column displaying a year after the participation date in date format?

View 1 Replies View Related

Adding Column To A Table Before An Existing Column

Mar 30, 2004

I simply need the ability using SQL to add columns in an existing table before (or after) columns that already exist.

The MS SQL implementation of ALTER TABLE doesn't seem to provide the before or after placement criteria I require. How is this done in MS SQL using SQL or is there a stored procedure I can use?

Thanks.

View 5 Replies View Related

Adding A Time Column To A Date Column

Jul 20, 2005

I have two columns in a table:StartDate DateTime and StartTime DateTime.The StartDate column holds a value such as 07/16/2004The StartTime column holds a value such as 3:00:00 PMI want to be able to add them in a stored procedure.When I use StartDate + StartTime I get a date two days earlier than expected.For example, instead of 7/16/2004 3:00:00 PM StartDate + StartTime returns7/14/2004 3:00:00 PM.Can anyone point out wht I'm doing wrong with this one?Thanks,lq

View 2 Replies View Related

Adding Date Column On First Column

May 2, 2014

I have a query like following

SET NOCOUNT OFF
SET ROWCOUNT 0
DECLARE @StartDate DateTime
DECLARE @EndDate DateTime
SET @StartDate = CAST (DATEDIFF(d, 0, DATEADD(d, 1 - day(getdate()), getdate()))as datetime)
SET @EndDate = GetDate()

[Code] ....

and when i execute it, it gave a return that i expected, but then i want to add a date column on the first column.

View 5 Replies View Related

Check For Column Before Adding A Column

Oct 8, 2007

How can I test to see if a column exists before adding a column to a sql mobile table?


thanks,

Luis

View 1 Replies View Related

Adding New Column

May 5, 2008

Hi,I have an application up and running. I need to add a new column to one of the tables which is currently being used - would adding a new column change or cause errors in the current application? e.g. if the table is being accessed by selecting * from table, will adding a new column cause an error? If there is any circumstance where an error would be caused by adding a new column, I will have to create an entirely new table. If I have to do this - how do I get a column in the new table to have the same values as a column in the old table? Can I create a computed column where column=oldcolumn? Thanks,Jon 

View 5 Replies View Related

Help With Adding Column

Jun 15, 2007

hi guys! I have a table with 3 columns but i realized that i need to add 1 column between column 2 and 3. Can anybody please help me on how to do that? Thanks in advance!

View 2 Replies View Related

Adding New Column

Jul 5, 2007

ALTER TABLE BFTITLE ADD COLUMN [RATETYPE] [NUMERIC] (10) NOT NULL ;

syntax is not working so can any one tell the right syntax

View 3 Replies View Related

Adding A New Column

Mar 20, 2007

Sanjeev Dhiman writes "Sir,
How I can add a new column between existing two column...?


Sanjeev Dhiman"

View 2 Replies View Related

About Adding A New Column...

Sep 12, 2005

Suppose I have a table with the following columns: Year, SalesInEurope,SalesInAmerica, TotalSales. I want to add a new column calledSalesInAsia, say, but I want it to appear before TotalSales. How canthis be achieved?Thanks,Bruno

View 13 Replies View Related

Adding 0 To A Column

Oct 26, 2006

Hi

I have a column with times in

845

930

1015

1145

I need to update the column to look like this:

08:45

09:30

10:15

11:45

thanks in advance

rich

View 1 Replies View Related

Adding Column In Resultset From SP

Dec 27, 2006

I have a sp: mysp_getstuff it contains the following:SELECT  Adress,City FROM tblUserData WHERE UserName='john'as you can see it returns 2 columns.I also have another SP: mysp_GetNr. This sp returns an integer.I want to call mysp_getnr from mysp_getstuff and add the result to the 2 columns in a column named 'Number'So the resultset from mysp_getstuff should be:Adress, City, Number (in which the number column contains the result from mysp_GetNr)How can I do that?

View 1 Replies View Related

Adding All Values In One Column

Oct 13, 2005

I posed this problem a few days ago, but havent been able to generate the results i need. Suppose my resultset from an sql query gathering totalsales for a given day by a salesrep looks like this:Lastname      totalsales  orderID-----------------------doe               1403         510doe                500          680 doe                 200          701using SUM(Accounts.totalsales) is not adding up the totalsales. What do I need to do to add up the totalsales, and then reassign it to a newfield?netsports

View 8 Replies View Related

Adding A Total Column

Jun 6, 2006

I have been working on a website in asp.net1.1 in vb.net2003.  I am using a sql2000 server.  I am attempting to add a column to my datagrid that will add the total number of wins and output the number in that colum.  With some help, I have been able to write the code. However, I am not sure where to put it. Is it a sql function I need to call from my code to add to the win column?  Thanks for your help.

View 1 Replies View Related

Adding Column To Table

Dec 18, 2001

I have a table size 2078mb, number of row +530,900. Is it normal for sql to lock users out of the db when I add a column to the end of the table? I'm running SQL 7.0. The table has 4 col regular indexes. No primary keys. It locked the user out for about 10 min. I thought with SQL 7.0 this problem went away?

View 1 Replies View Related

Adding Column !! Please Help .Urgent

Mar 26, 2002

Hello Everybody

We have a SQL Server 6.5 with SP 5a . I want to add an additional column in one of the tables of a database .
Since i don't have much experience on SQL 6.5 , i need your precious help in resolving this case .
Can somebody help me in this regard in a detail step wise manner ? Enterprise manager does not have facility to add new columns to an existing table in SQL 6.5 .
I want to add a Column called 'DM ' with datatype as 'bit' with size as 1 and as non nullable .
Any kind of help will be very precious to me .

Thank you all in advance.

Regards
Rita.

View 5 Replies View Related

Adding A Total Column

May 16, 2002

This is a very simple select but I would like to add a final column that adds the QOH, QOB, QOO and Quantity. How can I accomplish this? Thanks
SELECT DISTINCT
zcus_MM_Medsurg_Used.stock_no,
zcus_MM_Medsurg_QOH_Only.qty_on_hand AS QOH,
zcus_MM_Medsurg_Used.QOB,
zcus_MM_Medsurg_Used.QOO,
zcus_MM_Medsurg_Used.QUANTITY

FROM
zcus_MM_Medsurg_QOH_Only INNER JOIN
zcus_MM_Medsurg_Used ON
zcus_MM_Medsurg_QOH_Only.stock_no = zcus_MM_Medsurg_Used.stock_no

View 1 Replies View Related

Adding A Column To A Table

Feb 24, 2003

Can I add a column to a database table without dropping and recreating the table?

The problem is that everytime a user creates an action that requires a new table - at the moment I drop the table and recreate the table with the new column.

This requires lots of resources as I have to populate the table again.

Is there a design way I can go around this?

View 5 Replies View Related

Adding A BIT Column - 100+ Hours!

Jul 7, 2004

I previously posted about a problem where I added a non-NULL DEFAULT 0 bit column to a table with 80 million records. It was taking a LONG time and we needed that database up fast. It ended up taking a total of 17 hours.

Now my coworker added the same non-NULL DEFAULT 0 bit column to another table on another important server. But this table has more like 400 million rows. It's been running for 100+ hours and is still going. We were hoping it would scale linearly (5*80 million records would hopefully take 5*17 hours) but that isn't happening. I have no idea how much longer it will take. I really need this to be done. I'm tempted to cancel but that will incur a potentially massive rollback, right? Any guestimate on how large that would be?

Any ideas?

View 9 Replies View Related

Adding A Column Then Using It In A Script

Jan 20, 2004

Hi,
I would like to alter a table in a sql server database then update the column with data in the same script. However, the database does not recognize the database column if I create it within the script. Is there a way to refresh this within the script so that I can run this in one procedure? If I create the table in one script then update in a second script it will work. Thanks.


Laura

View 5 Replies View Related

Adding A SUM Column To Query

Oct 29, 2013

I have a pretty simple SQL query that has two columns that contains only numbers. Is there a way i can add an extra column that simply subtracts the number in one column from number in the other column.I query the data tables rather than have a live link so the .csv file gets overwritten every time i run the query.

View 4 Replies View Related

Problem With Adding A New Column

Aug 27, 2005

hello friends!

I hav a table..which has 4 columns and 5 rows..

whenever i add a new column it goes to end of the table..

Now i want to add a new column in between 2nd and 3rd column..

Is there a way to add a new column to a specified place in a table??

THANKYOU!

View 4 Replies View Related

Adding Auto_increment Id Column

Aug 17, 2007

i'm trying to add an 'id' column that will auto_increment in a table that i've set up in sql enterprise server. i tried using the code:

ALTER TABLE tablename ADD id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST

however, i get the following error:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'ID'.

could someone please help (ASAP!!!) with how to fix this.
thanks in advance for any help.

View 1 Replies View Related

Adding A Column With Not Null

Sep 4, 2007

Hi All,
I've one table named tableAB. in that i've added one new column with not null option in the enterprise manager. then i've generated the script, and run the script in client database. because already data is there, it is not accepting to put null value in the new column. so the is missing. anyway backup is there with me.

what is the solution for this....

thanks in advance

View 10 Replies View Related

Adding Column To Sp_helpuser

Sep 11, 2007

I am working on creating a configuration database. This will connect to many databases on many different servers. What I would like to do is run sp_MSForEachDB then store the name of the current server and database the package is connected to. Then add both of these into a column before running sp_helpuser. I don't know how confusing this is, but I think I may have the code worked out pretty well. If you have any questions, please post them and I will try to answer as best as I can. What I would like the ending result to look like is...

<server1> <database1> <userID1> <datareader>
<server1> <database1> <userID1> <datawriter>
<server1> <database1> <userID2> <datawriter>
<server1> <database2> <userID1> <datawriter>

I am at a loss, and I can't use the sys.<table> tables because it has to be backward compatible. Thanks for any help in advance.

View 1 Replies View Related

Adding Additional Column

Feb 29, 2008

Hi All,

I have developed a report using report viewer in asp.net web form. The report is generated based on the selection of Department. User have an option to multi select the departments so the department column grows. Lets say user select Business category first and generate the report then user decides to add another department say Engineering. No the report column headers will have addional column "Engineering". I have used the Matrix since I had to group by Name and dates. Everything is good so far.
Now I have to add an additional column "Notes" at the end of all the columns. If there is ony department is chosen then Notes column appears after that and if mulitple departments are chosen the Notes column should also appear after all the department column (at the very end).
I am really having hard time to accomplish this. Is there any suggestion or solution to finish this? I really appreciate your responses.

Thank you.

View 1 Replies View Related

Adding A New Column Is DBNULL

Jun 2, 2007

Hello,

VS 2005

I am developing the database application. This is a live database and is being used by the customer. I am to release a new version and I had to add new columns to fit the requirements DateStarted (DateTime), and TotalHours(Int) into a database table.There are already over a 1000 rows in this table.

When the customer wants to look at a record in this table and insert the value into the text boxes (Front-end), when it gets to the DateStarted or TotalHours it comes up with a error message:"

The value for column 'DateStarted' in table 'IncidentTask' is DBNull."The method for inserting is:



Code Snippet

Me.dtDateStarted.Value = Me.DsIncidentsControl.IncidentTask(0).DateStarted

What are the possible solutions to this problem? Would it mean checking for a DBNULL before displaying in the textboxes? Or updating the new column rows with an date:




Code Snippet

UPDATE IncidentTask SET DateStarted = '1/1/2005' WHERE (DateStarted IS NULL)

Many thanks for any suggestions,

Steve

View 1 Replies View Related







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