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
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.
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
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!
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
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
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).
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.
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
' Add Some Parameter Dim someParameter As Parameter = New Parameter("someParameterName", TypeCode.String) someParameter.DefaultValue = New String("Some Value") someParameter.Direction = Data.ParameterDirection.Output
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
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
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.
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.
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.
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 */
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.
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^
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?
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...
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
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,
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
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.
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!
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
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
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