Control Over Select Output Results

Jul 20, 2005

Hi All !

Is it possible to get rid of these dash symbols which are underlining
the column name when recordset is returned after query execution ?

For example, using isql.exe:

SELECT 'blah'
go

produces the following results:

----
blah

What I want to achieve is just
blah

I know that SET NOCOUNT ON switches the "X row affected" thing. But
how about column headers ?

Thanks for your time,


Seeker

View 5 Replies


ADVERTISEMENT

Output Select Results To A Text File.

Jul 23, 2005

I have a dynamic database that will be periodically queried to selectthe data from a blob field. This blob data field is text of a variablelength. The data will be selected using an id field and a date range.There will be multiple blob fields returned that I would like to outputinto a txt file in a local folder.I have the blob fields showing up as text in the field and not areferring link. Can someone point me to an output to text solution?Thanks

View 1 Replies View Related

Control Output Of Stored Procedure

Feb 19, 2008

I have a very simple stored procedure that returns a list of employees. The procedure works fine. However, sometimes there is no records returned. In that case, I'd like to like the procedure to return a single record with predetermined values. I've added the YELLOW portion of the code to my existing proc to reflects the logic of what I am trying to accomplish.


CREATE PROC proc_Emp

@Sel_Country
AS
BEGIN


SELECT DISTINCT employee, hrid
FROM emp_table
WHERE country = @Sel_Country


@SEND_RESULTS =
CASE WHEN row_count = 0 THEN

SELECT 'No Country', 4444444444
ELSE

(send original results)
END


END

I need to:



Query for the employee list

If the row count is zero/null then return fixed values

Else return the orginal data from Step 1.
I'm guessing I need to use the OUTPUT command and configure some variables. But I'm not having much luck decoding BOL and I've not found any similar submissions to the forum.

Rob

View 7 Replies View Related

Control The Output Of Stored Procedure

Nov 14, 2007



Hi all,
I have a several stored procedures that they are designed to do Update and Insert tasks and all of them after finishing the task will return the Inserted or Updated row.
The problem is sometime I would need to call the stored procedure inside other ones and somehow i need to stop the inner stored procedures from producing resultsets. I don't find any SET options in SQL documentation which could control this behavior and block resultsets from being sent to the client.

Is there any way i could do this?


Exmaple:
In following example as a result of dbo.AddressInsert being called within dbo.CustomerInsert, two resultsets are returned to the client!

Procedure dbo.AddressInsert(....)
as
BEGIN

Insert INTO Adress ....

SELECT * FROM AdressView WHERE AddressID = @@identity
END

Procedure dbo.CustomerInsert(...)
as
begin
-- transcation begin...

EXEC dbo.AddressInsert

INSERT INTO Customer....

-- end transcation

SELECT * FROM Customer WHERE CustomerID = @@identity

end

View 4 Replies View Related

How Lmit - Control Output Of Dtexec ?

Nov 29, 2006

Hi,

we have job that execute SSIS (s) using dtexec and save output(s) to file

Output of SSIS is 4 page long full of entries like

Validating: 0% ..ProgressProgress: .. Prepare for Execute: 100%

1. Can I limit output to show only success or failure ?
2. Can I redirect output of dtexec to be saved in msdb insted of showing after execution.


Thank you

Alex







View 1 Replies View Related

Is There A Way To Hold The Results Of A Select Query Then Operate On The Results And Changes Will Be Reflected On The Actual Data?

Apr 1, 2007

hi,  like, if i need to do delete some items with the id = 10000 then also need to update on the remaining items on the with the same idthen i will need to go through all the records to fetch the items with the same id right?  so, is there something that i can use to hold those records so that i can do the delete and update just on those records  and don't need to query twice? or is there a way to do that in one go ?thanks in advance! 

View 1 Replies View Related

Control Characters Output In Attachments From Xp_sendmail

Jul 20, 2005

I have been testing our SQL Mail setup in SQL Server 2000 (sp3a) andhave found that when I attach results as a file, every other characteris a control character which causes each real character output on aseparate line. I have no idea why this is happenening, I've never seenit before.The code looks like this;EXEC master.dbo.xp_sendmail@recipients = '<email address>',@dbuse = 'TestDB',@query = 'select top 50 descr from AdTable',@message = 'nathan email test',@subject='SQL Mail test',@attach_results = 'true',@width = 100,@separator = ','The results look like this! -descr-----etc.When I view the result text file with an advanced text editor I cansee that every other character is a control - these characters are notin the data, I have already checked this, so it looks like its theyare being created by SQL Server or the mail system? Any advice muchappreciated.Nathan

View 6 Replies View Related

Binding Render Output To ReportViewer Control?

Jul 13, 2006

I'm trying to take the output of the Render method and bind it to the ReportViewer control. First of all, is this possible? If so, what is the best way to render the report (format: XML,CSV, NULL, etc), and then how to I 'bind' the result to the control?

I'm proving some code to demonstrate how I'm rendering the report:
...
string format = "XML";
string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
ReportExecutionService rs = new ReportExecutionService();
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
byte[] result= null;

rs.ExecutionHeaderValue = execHeader;
execInfo = rs.LoadReport(path, null);
string SessionId = rs.ExecutionHeaderValue.ExecutionID;
result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);


Thanks, any help would be greatly appreciated.
Peter

View 2 Replies View Related

Incomplete Print Output From ReportViewer Control

Dec 29, 2006

We are experiencing a problem where a server report is rendered in the
ReportViewer control successfully but when the user chooses to print the
content, the print output is incomplete (ex. only 18 of 23 pages are printed,
etc.).

This is happening consistently and has been reproduced for multiple
different reports. It does not happen if the same report is printed via the
Report Manager web interface.

I have also found that if I switch to Print Layout mode and then initiate
the print from the ReportViewer that the problem does not occur. This is our
current workaround, but it would be nice to know what is causing this and
have it fixed.

Has anybody else seen this? Is this a known issue with my current version
(SQLRS 2005 with SP1 applied).

Thanx in advance.

View 3 Replies View Related

Output SP Results To File

Jan 20, 2000

What would be the correct synatx if I wanted to output the results of a stored to a file
instead of printing?

View 1 Replies View Related

Email Job Output Results

Apr 14, 2008

Hi,

I was wondering is there was is a way in SQL 2005 to not only email job completion notifications but also include the output of a step (e.g. TSQL step) within the email. I was able to accomplish this in the past with SQL 2000 by writing output to a file and then adding an extra CMDEXEC step that exectuted BLAT (CLI SMTP engine) that sent the contents of the output file as email body out of band. Although this worked and I can do the same with 2005 it is not very elegant and I was wondering if 2005 version might have something built-in.

Any thoughts?

Thank you,


-Ed

View 1 Replies View Related

How Do I Retrieve Results Of The Output Parameters??

Feb 17, 2008

I am able to perform my Stored Procedure, but I can't figure out how to get access to the OUTPUT parameters!Here is my code:   Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim mySqlDataSource As SqlDataSource = New SqlDataSource

mySqlDataSource.InsertCommandType = SqlDataSourceCommandType.StoredProcedure

mySqlDataSource.ConnectionString = "my connection string"

mySqlDataSource.InsertCommand = "MyStoredProc"

mySqlDataSource.InsertParameters.Add("someId", TypeCode.Int16, 166)

mySqlDataSource.InsertParameters.Add("someNumber", TypeCode.Int16, 4)

' Add Some Parameter
Dim someParameter As Parameter = New Parameter("someParameterName", TypeCode.String)
someParameter.DefaultValue = New String("Some Value")
someParameter.Direction = Data.ParameterDirection.Output

mySqlDataSource.InsertParameters.Add(someParameter)

mySqlDataSource.Insert()


End Sub
  Any ideas as to how I get the new value that was "hopefully" assigned to someParameter??? Thanks for any help 

View 3 Replies View Related

EXEC @SQLString With Output Results

Jun 2, 2005

Hello, I have been working around this issue, but couldn't yet find any solution.I have a stored procedure that calls a method to do a certain repetitive work.In this function, I have a dynamic query, which means, that I am concatinating commands to the query depending on the input of the function.for example, there is an input for a function called "Id"Inside the function, if Id = 111I need to add " and ID <> 1" and if Id has another value I need to add " and ID = c.ID" something like that.Now, inside the function, I need to return a value by executing the above @SQLString as follows:EXEC @SQLStringWhen I need is something likeEXEC @SQLString, @Total OutputReturn (@Total)Are there any ideas ?regards

View 1 Replies View Related

Output Results Of Query To A Txt File

Apr 3, 2001

I have come across manual queries being run daily and the results saved to a txt file on the network.

I basically want to set run these up a stored procedure and set up as a scheduled task to run daily.

Does anyone know if you can automatically save the results of a query/stored procedure to a text file on a network??

Many Thanks..

View 1 Replies View Related

Transact SQL :: Possible To Use Results From OUTPUT And Use Them As Parameters?

May 28, 2015

I am trying to create a proc and at the end of the proc I want to call another proc and pass to one of the parameters to proc using the result from the "OUTPUT". Is it possible to use the results from the "OUTPUT" and use them as parameters?

USE [MyDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON

[code]....

View 16 Replies View Related

SELECT-Using Correlated Subqueries: Just Name In Results &&amp; 0 Row Affected In One Of MSDN2 SELECT Examples

Jan 11, 2008

Hi all,
I copied and executed the following sql code in my SQL Server Management Studio Express (SSMSE):
--SELECTeg8.sql from SELECT-Using correlated subqueries of MSDN2 SELECT Examples--

USE AdventureWorks ;

GO

SELECT DISTINCT Name

FROM Production.Product p

WHERE EXISTS

(SELECT *

FROM Production.ProductModel pm

WHERE p.ProductModelID = pm.ProductModelID

AND pm.Name = 'Long-sleeve logo jersey') ;

GO

-- OR

USE AdventureWorks ;

GO

SELECT DISTINCT Name

FROM Production.Product

WHERE ProductModelID IN

(SELECT ProductModelID

FROM Production.ProductModel

WHERE Name = 'Long-sleeve logo jersey') ;

GO

=========================================
I got:
Results Messages
Name o row affected
========================================
I think I did not get a complete output from this job. Please help and advise whether I should search somewhere in the SSMSE for the complete results or I should correct some code statements in my SELECTeg8.sql for obtaining the complete results.

Thanks in advance,
Scott Chang

View 5 Replies View Related

Output A File With Results Of Stored Procedure

Feb 3, 2008

I have a stored procedure that outputs an XML result. As it is right now, I will periodically go into SQL Server Mngmnt Studio and run the procedure, then save the XML output to an XML file that my website uses. The procedure takes too long run (it is recursive through the entire data set) to have the website call the procedure on its own, and wait for the results.

My question is this: Can I create a trigger that will run this stored procedure and save the results to a file? Is that possible? The trigger would call the procedure any time a specific table is updated (which will be a rare occurrence), then save the file to the path provided so the website users could always have the most up-to-date information without having long wait times caused by long waits for the procedure to run.

Any advice on how best to accomplish this will be appreciated.
Thanks in advance.

View 1 Replies View Related

How To Output Results To Grid In C# Stored Procedure

Oct 30, 2007



When I run my CLR/C# stored procedure inside Visual/BI Dev Studio, the results in a datatable are sent over pipe and displayed in output window without the grid format. I looked up inOptions and settings but couldn't find a way to change the format of output window to grid. I would like to be able to do that so I can copy/paste the results in excel.

View 4 Replies View Related

Implement SELECT Starement On A Results Of Prev SELECT

Dec 22, 2002

Hi,
im getting from my first select a list of pairs of codes (let say the codes r of products.)
so i have something like:

FirstCode SecondCode
1 1
2 5
4 2
... ...
now i want to get the name of each product so it whould be like:

FirstCode,FirstName,SecondCode,SeconeNam

the names stored in other table.
how can i do it?
thanks

Dovalle

View 1 Replies View Related

Generating Dependencies But Will NOT Produce Any Output In Both Results And Messages Tabs

Mar 16, 2015

I am rewriting several stored procedures that originally had lots of "multiplicated" code. I am aware that references to objects within dynamic SQL do not create dependencies, so I intend to add code that will generate the dependencies but will NOT produce any output in both the Results and Messages tabs, not be overly "messy" or complicated, and have the least impact on execution plan creation as possible.

As we use a dependency list of tables used to our support staff pinpoint possible data issues associated with each of these stored procedures.

I have tried a few methods already, including this:

SET @SQL = N'SELECT Column1,Column2 FROM dbo.TableName';
...
/***************************************************************************************/
/* This code block is only to establish dependency of objects used within dynamic SQL. */
/* */
/* SET statements are used so that no output is produced in Results or Messages tabs. */
/* Object existence check avoids error 208, "Invalid object name" message. */
/***************************************************************************************/
DECLARE @DependentObject SQL_VARIANT;
IF OBJECT_ID(N'dbo.TableName', N'U') IS NOT NULL
SET @DependentObject = ( SELECT TOP (1) Column1,Column2 FROM dbo.TableName);
/* End code for dependency of objects used within dynamic SQL */

View 2 Replies View Related

SQL Server 2008 :: Query Results Output Into CSV File To Use In VBA Macro

Jul 31, 2015

I have the following code below where I need to have all of the query results output into a .csv file to use in a VBA macro. The issue I am running into is that the data is not deliminating correctly and my rows are being shifted incorrectly. Any better way of out putting the results into a .csv file with a common delimiter.

-- Declare the variables
DECLARE @CMD VARCHAR(4000),
@DelCMD VARCHAR(4000),
@HEADERCMD VARCHAR(4000),
@Combine VARCHAR(4000),
@Path VARCHAR(4000),
@COLUMNS VARCHAR(4000)

[Code] ...

Output from query (please post in a text editor. The line starting with (only ) should be on line 1 after 20 pks and is shifted to a new line.):

557898^1^9885E25^80082^9.0 CM GLASS FIBER PADS 20PKS
(only 12 pks in stock that will ship today)
^12.00000000^.00000000^18.32000000^219.84000000000^28.30000000
^339.60000000000^9.98000000^35.2650176678445^DR9146322^0^

[Code] ....

View 1 Replies View Related

Sql Server 2005 Sql Statment To Output Query Results To A File

Jan 21, 2008



I am using vs 2005 and sqlserver 2005 to manage a large database. I need to create a series of text files based on the value of one of the columns. Is there an sql command that will pipe the output directly to a file?

Thanks,
Mike

View 1 Replies View Related

Transact SQL :: Pass Results From Select To Another Select

Oct 13, 2015

I've got a select as follows:

select computer, count(*) as MissedCount  from WInUpdates_Neededreq
WHERE LoggedDate BETWEEN DATEADD (DAY, - 5, GETDATE()) AND GETDATE() and LastReportTime !< DATEADD (DAY, -5, GETDATE())
group by computer

I need to make a join onto another table but don't want to lose the coutn(*) as MissedCount.

How can I join to another table and still keep the count form the original table.  I want ot join to tblogons.workstationname and return computer from the original query...

View 16 Replies View Related

Stored Procedure | Selects Some Data |query The Results It Created And Output

Dec 2, 2005

I can create 1 view of a database then use that views results to query

but i want do this with a stored procedure
pass some data to it, so it selects some data

query the results it created and output this data.

ie


pass 2 values to the procedure
(
@FirstValue int,
@secondValue int output

)


select from a database with the firstpassed value

Select *
From TableName
Where ID = @FirstValue

Then
using the results from the above select

Select *
From theResultsOfAbove
Where ID = @SecondValue

any ideas would be fabo !

View 6 Replies View Related

SQL Server 2008 :: DBMail Output Query Results As CSV With Headers But No Separator

Aug 25, 2015

If I use msdb..sp_send_dbmail or save query results as text (using sqlcmd) and include the column headers I get the dashed separator line.

e.g.

custID, name
------, ------
1,bob
2,jamesI would like this
custID, name
1, bob
2 ,james

I found this method [URL] ....

::
sqlcmd -E -S (local) -d myDB -W -w 1024 -s "," -i "SELECT * FROM tblCust" | findstr /V /C:- /B > C: emp.csv

Can the same result be achieved sending as attachment with dbmail?

EXEC msdb..sp_send_dbmail @attach_query_result_as_file = 1I don't want to have to add column names as part of the query

Change the query to return column headers in resultset
SELECT 'CustID' as f1, 'name' as f2
UNION ALL
SELECT CAST(CustID as Varchar(10)), name FROM tblCustand set

msdb..sp_send_dbmail @query_result_header = 0

View 0 Replies View Related

SQL Server 2012 :: Run Script Within A Table / String And Output Results To File?

Sep 21, 2015

I have been given a request at work that requires us to run the SQL scripts that are held in a report configuration table and output the results as .csv or.xls files in a desired folder with a file name that is also specified within the report config table.

An example of the table is as per script below with column A being the desired file name to be created and Column B contains the script that will be executed.

Ideally I require a script that i can drop into a Stored Proc that will run down each row in the table and export and create each rows results as a separate file in a desired folder.

------------------------------------------------------------------------------------------
-----SAMPLE TABLE SCRIPT -----------------------------------------------------------
------------------------------------------------------------------------------------------
/****** Object: Table [dbo].[Test_Table_PS] Script Date: 21/09/2015 09:14:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Test_Table_PS](
[File_Name] [nvarchar](100) NULL,

[Code] ....

View 7 Replies View Related

SELECT Statement Beyond My Control!

Aug 11, 2005

I have been struggling with a query for sometime now, so I though I would see if anyone could help me out.Here is what I am trying to accomplish:  I have a reservation page that has a dropdown list control on it.  I am trying to populate the dropdown list with the available areas that have not already been reserved for the day.  I have two tables, one of them contains the list of all of the areas that can be reserved.  The second table contains the current reservations.Please let me know if I have not explained myself well enough and i will try to do expound better.Here is what I have so far, but it seems to give me results for the entire table, not just that day in particular.  SELECT    tbl_Hunting_Area.Area, tbl_Hunting_Area.Area_ID, tbl_Blinds.Area_ID, tbl_Blinds._DateFROM      tbl_Hunting_Area CROSS JOIN tbl_BlindsWHERE     (tbl_Hunting_Area.Area_ID <> tbl_Blinds.Area_ID) AND   tbl_Hunting_Area.Area_ID NOT IN   (SELECT tbl_Blinds.Area_ID FROM tbl_Blinds AS tbl_Blinds_1 WHERE   (tbl_Blinds._DATE = '8-11-2005'))Here are the results that I receive from this query:Goose Field #2 2 1 2005-08-09 00:00:00.000Goose Field #3 3 1 2005-08-09 00:00:00.000Goose Field #4 4 1 2005-08-09 00:00:00.000Pond #1 - Pit Blind 5 1 2005-08-09 00:00:00.000Pond #1 - Shore Blind 6 1 2005-08-09 00:00:00.000Pond #2 7 1 2005-08-09 00:00:00.000Goose Field #1 1 6 2005-08-09 00:00:00.000Goose Field #2 2 6 2005-08-09 00:00:00.000Goose Field #3 3 6 2005-08-09 00:00:00.000Goose Field #4 4 6 2005-08-09 00:00:00.000Pond #1 - Pit Blind 5 6 2005-08-09 00:00:00.000Pond #2 7 6 2005-08-09 00:00:00.000Goose Field #1 1 7 2005-08-11 00:00:00.000Goose Field #2 2 7 2005-08-11 00:00:00.000Goose Field #3 3 7 2005-08-11 00:00:00.000Goose Field #4 4 7 2005-08-11 00:00:00.000Pond #1 - Pit Blind 5 7 2005-08-11 00:00:00.000Pond #1 - Shore Blind 6 7 2005-08-11 00:00:00.000Goose Field #1 1 5 2005-08-11 00:00:00.000Goose Field #2 2 5 2005-08-11 00:00:00.000Goose Field #3 3 5 2005-08-11 00:00:00.000Goose Field #4 4 5 2005-08-11 00:00:00.000Pond #1 - Shore Blind 6 5 2005-08-11 00:00:00.000Pond #2 7 5 2005-08-11 00:00:00.000

View 8 Replies View Related

Select Command Control Parameters

May 12, 2008

 SelectCommand="SELECT [id], [ref_id], [ref_name] FROM [ref] where [delete_flag] = 'N' AND [flag_transmit] = 'N' AND [ref_name] = @ref_name ">

<asp:ControlParameter Name="ref_name" ControlId="SrchRefName" PropertyName="Text" ConvertEmptyStringToNull="false"/>

   The gridview of all the records is displayed on the page by default. There is a lookup of SSN and Name and putting values in those fields should filter the records and display only the row containing entered Name.I have trouble with the SelectCommand.  No gridview is displayed with the above command even if value is entered in the Lookup textBox (SrchRefName).But when I change the selectcommand to- (using OR) SelectCommand="SELECT [id], [ref_id], [ref_name] FROM [ref] where [delete_flag] = 'N' AND [flag_transmit] = 'N' OR [ref_name] = @ref_name ">  <asp:ControlParameter Name="ref_name" ControlId="SrchRefName" PropertyName="Text" ConvertEmptyStringToNull="false"/> the default gridview is displayed with all the records even though a value is entered in the lookup text box. Please help.  

View 2 Replies View Related

SELECT WHERE RowID Is Not From Results Of Another SELECT

Nov 16, 2007

I have one query which uses a join query to gather all the projects that should show up in someone's list over a period of time (returns and id (int) and name (varchar) paired dataset). I want to do a separate query that takes that list and selects all projects (same paired set ... id and name) EXCEPT where it matches an id on a row of the given result set. The one query looks like this ..DECLARE @startDate datetimeDECLARE @endDate datetimeDECLARE @userId UNIQUEIDENTIFIERSELECT @startDate = ppStartDate FROM ppTablewhere payPeriodID = @payPeriodIDSELECT @endDate = ppEndDate FROM ppTable WHERE payPeriodID = @payPeriodIDSELECT @userId = userID FROM usersTable WHERE userName = @userNameSELECT DISTINCT p.projectID, p.projectNameFROM projectsTable pLEFT JOIN projectMemberhsip m ON m.ProjectId = p.ProjectIdLEFT JOIN timeEntryTable t ON t.ProjectID = p.ProjectIdWHERE t.TimeEntryUserId = @userID AND t.TimeEntryDate >= @startDate AND t.TimeEntryDate <= @endDateORm.UserId = @userID I want to get the same selection from projectsTable WHERE it's not anything from this result set.Haven't been able to get it by modifying the WHERE logic.  Is there a way to select all WHERE id != (resultSet from this SELECT)? TIA! 

View 5 Replies View Related

Control Number Of Options Selected In A Multi Select Parameter

Feb 13, 2007

Hi All

I have a report which has a multi-value parameter. Problem is, it can contain up to 100 options.Is there a way to limit the number of options that is passed to the SQL statement?. EG list has 100 options, user selects 10 but only the first 4 selected options are passed to the SQL statement.
Many Thanks
Delli

View 4 Replies View Related

Select Output

May 7, 2002

Another question for all you SQL experts, I have a lot of them. I am trying to select from a table wher some conditions need to be met based on an employee ID. What I am doing is when the rank is a 1,2, or 3 I pick up the text description of that rank. Can I make it so that I get the ID only once and all the text descriptions are on the same line. Here is the sql script along with my current output and my desired output.



--SQL SCRIPT__

select C.empID, B.Rank,B.Text1 as Skills from tbl_survey_rank B , tbl_survey_valueID C
where PATINDEX ( '%'+ltrim(rtrim(B.valueID))+'%', C.text1) >0 and C.empID = '2924'and
(B.Rank ='1'or B.Rank ='2' or B.Rank ='3')


--CURRENT OUTPUT--

empID Rank Skills
------- ---- --------------------------------------------------
2924 1 Create Documents
2924 2 Mail Merge
2924 3 Create Header and footer
2924 3 Create Spreadsheet
2924 3 Joining Tables in a Query



--DESIRED OUTPUT--

empID Rank Skills
------ ---- ------------
2924 1 Create Documents
2924 2 Mail Merge
2924 3 Create Header and footer, Joining Tables in a Query, Create Spreadsheet

View 1 Replies View Related

Select Output With Cursor

May 8, 2002

In my previous post I asked how to do the bottom question. I got a response to use a cursor, now I made an attempt to use a cursor but I still get the same response. Any help will be greatly appreciated.


--CURRENT OUTPUT--

empID Rank Skills
------- ---- --------------------------------------------------
2924 1 Create Documents
2924 2 Mail Merge
2924 3 Create Header and footer
2924 3 Create Spreadsheet
2924 3 Joining Tables in a Query



--DESIRED OUTPUT--

empID Rank Skills
------ ---- ------------
2924 1 Create Documents
2924 2 Mail Merge
2924 3 Create Header and footer, Joining Tables in a Query, Create Spreadsheet


--Here is the cursor script.--

Declare @skills varchar(255),@skills2 varchar(255),@message varchar(255),@empID varchar(255), @Rank varchar(255)
DECLARE emp_skills CURSOR For
select C.empID, B.Rank,B.Text1 as Skills from tbl_survey_rank B , tbl_survey_valueID C
where PATINDEX ( '%'+ltrim(rtrim(B.valueID))+'%', C.text1) >0 and C.empID = '2924'and
(B.Rank ='1'or B.Rank ='2' or B.Rank ='3') or PATINDEX ( '%'+ltrim(rtrim(B.valueID))+'%', C.text1) >0 and
B.Rank ='3'and C.empID = '2924' or PATINDEX ( '%'+ltrim(rtrim(B.valueID))+'%', C.text1) >0 and
B.Rank ='3'and C.empID = '2924' or PATINDEX ( '%'+ltrim(rtrim(B.valueID))+'%', C.text1) >0 and
B.Rank ='3'and C.empID = '2924' or PATINDEX ( '%'+ltrim(rtrim(B.valueID))+'%', C.text1) >0 and
B.Rank ='3'and C.empID = '2924'

DECLARE emp_skills2 CURSOR For
select B.Text1 as Skills from tbl_survey_rank B , tbl_survey_valueID C
where PATINDEX ( '%'+ltrim(rtrim(B.valueID))+'%', C.text1) >0 and C.empID = '2924'and
(B.Rank ='1'or B.Rank ='2' or B.Rank ='3') or PATINDEX ( '%'+ltrim(rtrim(B.valueID))+'%', C.text1) >0 and
B.Rank ='3'and C.empID = '2924' or PATINDEX ( '%'+ltrim(rtrim(B.valueID))+'%', C.text1) >0 and
B.Rank ='3'and C.empID = '2924' or PATINDEX ( '%'+ltrim(rtrim(B.valueID))+'%', C.text1) >0 and
B.Rank ='3'and C.empID = '2924' or PATINDEX ( '%'+ltrim(rtrim(B.valueID))+'%', C.text1) >0 and
B.Rank ='3'and C.empID = '2924'
OPEN emp_skills
OPEN emp_skills2
FETCH NEXT FROM emp_skills into @empID, @Rank, @skills
FETCH NEXT FROM emp_skills2 into @skills2
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @message = @skills2
FETCH NEXT FROM emp_skills2 into @skills2
Print @empID + ' '+ @Rank + ' ' + @message


FETCH NEXT FROM emp_skills into @empID, @Rank, @skills

End
CLOSE emp_skills
DEALLOCATE emp_skills
CLOSE emp_skills2
DEALLOCATE emp_skills2


--Previous Post--

Another question for all you SQL experts, I have a lot of them. I am trying to select from a table wher some conditions need to be met based on an employee ID. What I am doing is when the rank is a 1,2, or 3 I pick up the text description of that rank. Can I make it so that I get the ID only once and all the text descriptions are on the same line. Here is the sql script along with my current output and my desired output.



--SQL SCRIPT__

select C.empID, B.Rank,B.Text1 as Skills from tbl_survey_rank B , tbl_survey_valueID C
where PATINDEX ( '%'+ltrim(rtrim(B.valueID))+'%', C.text1) >0 and C.empID = '2924'and
(B.Rank ='1'or B.Rank ='2' or B.Rank ='3')


--CURRENT OUTPUT--

empID Rank Skills
------- ---- --------------------------------------------------
2924 1 Create Documents
2924 2 Mail Merge
2924 3 Create Header and footer
2924 3 Create Spreadsheet
2924 3 Joining Tables in a Query



--DESIRED OUTPUT--

empID Rank Skills
------ ---- ------------
2924 1 Create Documents
2924 2 Mail Merge
2924 3 Create Header and footer, Joining Tables in a Query, Create Spreadsheet

View 2 Replies View Related

How To Put Select Output Into Different Columns?

Oct 27, 2004

I have a table like:

ID Disc
----------------
1 BUSH
2 JOHN
1 GOLE
2 MIKE

I would like output depending on ID to put Disc into two columns. Like:

ID Disc1 Disc2
----------------------------
1 BUSH NULL
2 NULL JOHN
1 GOLE NULL
2 NULL MIKE

Any help will be appreciated. Thanks

ZYT

View 2 Replies View Related







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