I'm trying to create a dynamic pivot table, with changing column headers eg. dates!!? how can this be done when you have to define the headers names in the query!
What I am trying to accomplish is to make a few extra columns with specified date ranges.
I have FY14 date range in the parameters at the top .. I would like to add a FY 15 column so the year would move up by 1.and also I need to add 2 more columns Prior year current month and This year, current month.
<code> DECLARE @Fy14_start datetime DECLARE @Fy14_end datetime SET @Fy14_start = '2013-07-01' SET @Fy14_end = '2014-06-30' SELECT x.ACCOUNT_NAME, X.STATUS_CODE, COUNT(X.PATIENT_CODE) AS FY14
Hi, I have a need to display on screen AND email a pdf report to email addresses specified at run time, executing the report with a parameter specified by the user. I have looked into data driven subscriptions, but it seems this is based on scheduling. Unfortunately for the majority of the project I will only have access to SQL 2005 Standard Edition (Production system is Enterprise), so I cannot investigate thoroughly.
So, is this possible using data driven subscriptions? Scenario is:
1. User enters parameter used for query, as well as email addresses. 2. Report is generated and displayed on screen. 3. Report is emailed to addresses specified by user.
I need to pull data using input from one table in sql server 2005. I have to query against the sql server 2000 database and pull data into sql server 2005. I have a list of ids that I have to pass to a query to get the desired data. What is the best practice for this. Can I use SSIS or do I need to build an app in C#? Can somebody please reply back?
I'm setting up my SQL Server 2005 instances to use dynamic ports on one of my machines. What is the tcp port range used? I need to know the range so I can open the correct ports on my firewalls.
This is my problem: I have a dynamic web reference for a SQL Server UDF coded in C#, but I am unsure of where URL for the webservice is being read from.
I am working with SQL Server 2005 to create a User Defined Function, however I need to have a web reference to the SQLReportingService2005 web service. I will be distributing this function to my customers so I need this web reference to be dynamic.
Although the webservice says it is dynamic, I do not see a app.config file to place the changing URL. Does anyone know where a dynamic web service pulls the URL from in this case?
I have one table which holds all the information for the forms and i have another table which holds list of all the form fields. Now these two tables are mapped and that table give me list of all the fields in any forms.
To get the information about the users who filled different forms first i need to query the tblFormsToFormFields and get the list of all the fields for that form and then use that fields list in the select query to get the result.
In my report i need to provide the drop down with the list of all the forms and then display the information for all the customers for that particular form with the list of the form fields.
Is there in SSRS 2005 i can use C# or any programming language to create Columns in the report dynamically as there will be different fields for each form.
This works in SQL Server 2005:CREATE XML SCHEMA COLLECTION Version2_1 AS'<xs:schema xmlns="http://www.icpsr.umich.edu/DDI" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:doc="http://www.icpsr.umich.edu/doc" targetNamespace="http://www.icpsr.umich.edu/DDI" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:annotation> <xs:documentation> This is a w3c Schema "Technical Implementation" of the DDI Conceptual Specification. This schema is intended for use in producing electronic versions of codebooks for quantitative social science data. CVS Revision information: $Header: /cvsroot/ddi-alliance/ddi/w3c/Version2-1.xsd,v 1.10 2007/07/31 19:03:54 mdiggory Exp $ </xs:documentation> </xs:annotation></xs:schema>' This version, however, gives errors: DECLARE @sql VARCHAR(max)SET @sql ='CREATE XML SCHEMA COLLECTION Version2_1 AS <xs:schema xmlns="http://www.icpsr.umich.edu/DDI" xmlns:xs="http://www.w3.org/2001/XMLSchema"xmlns:doc="http://www.icpsr.umich.edu/doc" targetNamespace="http://www.icpsr.umich.edu/DDI"elementFormDefault="qualified" attributeFormDefault="unqualified"><xs:annotation> <xs:documentation> This is a w3c Schema "Technical Implementation" of the DDI Conceptual Specification. This schema is intended for use in producing electronic versions of codebooks for quantitative social science data. CVS Revision information: $Header: /cvsroot/ddi-alliance/ddi/w3c/Version2-1.xsd,v 1.10 2007/07/31 19:03:54 mdiggory Exp $ </xs:documentation></xs:annotation></xs:schema>'EXEC (@sql)Ultimately, I am trying to create a stored procedure that will take as parameters the name of the new schema and the .xsd file it comes from, so that I can use it in code. I am a novice, so all explanations would be greatly appreciated.Thanks,Ed Graham
We have an internal sql 2000 server that acts as the database backend for our Internet presence. I believe that the sql server can be accessed because of a firewall "exception" (?) that allows the external web server to talk to the sql server using a specific IP address and port (namely that of the sql server.)
Now we need to install a sql 2005 instance on the same box which needs to act as an Internet backend. The sql browser service will resolve all client requests to the default or named instance. But I read that the sql browser service assigns a "dynamic" port to the Instance! If that is the case, it's unlikely that, unless the firewall has all ports open for outgoing traffic, that the sql instance will be able to communicate with the web server.
My conclusion:
Leave the default instance (sql 2000) port at its current value; assign the named instance an unused port; Make sure the sql browser is running on the box! Tell the firewall guys to make an exception for the new port.
I'm attempting to write a script that I can execute accross 30 servers that will create a domain login and subsequently grant access to said account on all databases per server. The only problem that I'm running into is trying to dymanically create the login. Example source is below.
declare @sql varchar(1000)
declare @loginname varchar(50)
select @loginname = 'DOMAINaccountname'
set @sql = 'if not exists (select * from master.dbo.syslogins where name = N' + char(39) + 'DOMAINaccountname' + char(39) + ')' + char(10) + char(13)
I got your email address from your web cast. I really enjoyed the web cast and found it to be very informative.
Our company is planning to use SSIS (VS 2005 / SQL Server 2005). I have a quick question regarding the product. I have looked for the information on the web, but was not able to find relevant information.
We are getting Source data from two of our client in the form of Excel Sheet. These Excel sheets Are generated using reporting services. On examining the excel sheet, I found out that the name Of the columns contain data itself, so the names are not static such as Jan 2007 Sales, Feb 2007 Sales etc etc. And even the number of columns are not static. It depends upon the range of date selected by the user.
I wanted to know, if there is a way to import Excel sheet using Integration Services by defining the position Of column, instead of column name and I am not sure if there is a way for me to import excel with dynamic Number of columns.
Your help in this respect is highly appreciated!
Thanks,
Hi Anthony, I am glad the Web cast was helpful.
Kamal and I have both moved on to other teams in MSFT and I am a little rusty in that area, though in general dynamic numbers of columns in any format is always tricky. I am just assuming its not feasible for you to try and get the source for SSIS a little closer to home, e.g. rather than using Excel output from Reporting Services, use the same/some form of the query/data source that RS is using.
I suggest you post a question on the SSIS forum on MSDN and you should get some good answers. http://forums.microsoft.com/msdn/showforum.aspx?forumid=80&siteid=1 http://forums.microsoft.com/msdn/showforum.aspx?forumid=80&siteid=1
SQL Server 2000 SP4 to multiple SQL Server 2005 Mobile Edition on PDAs. My DB on SQL2k is published with a single dynamic row filter using host_name() on my 'parent' table and also join filters from parent to child tables. The row filter uses joins to other tables elsewhere that are not published to evaluate what data is allowed through the filter.
E.g. Published parent table that contains suppliers names, etc. while child table is suppliers' products. The filter queries host_name(s) linked to suppliers in unpublished table elsewhere.
First initial sync with snapshot is correct and as I expected - PDA receives only the data from parent (and thus child tables) that matches the row filter for the host_name provided.
However - in my scenario host_name <--> suppliers may later be updated E.g. more suppliers assigned to a PDA for use or vice versa. But when I merge the mobile DB, the new data is not downloaded? Tried re-running snapshot, etc., no change.
Question: I thought the filters would remain dynamic and be applied on each sync?
I run a 'harmless' update on parent table using TSQL e.g. "update table set 'X' = 'X'" and re-sync. Now the new parent records are downloaded - but the child records are not!
Question: I wonder why if parent records are supplied, why not child records?
If I delete existing DB and sync new, I get the updated snapshot and all is well - until more data added back at server...
Any help would be greatly appreciated. Is it possible (or not) to have dynamic filters run during second or subsequent merge?
I have tried building an Inline TVF, as I assume this is how it would be used on the DB; however, I am receiving the following error on my code, I must be missing a step somewhere, as I've never done this before. I'm lost on how to implement this clr function on my db?
Error: Msg 156, Level 15, State 1, Procedure clrDynamicPivot, Line 18 Incorrect syntax near the keyword 'external'. CREATE FUNCTION clrDynamicPivot ( -- Add the parameters for the function here @query nvarchar(4000), @pivotColumn nvarchar(4000),
CREATE PROCEDURE dbo.spinb_CheckYN @FnNameYN varchar(50), @InvLineID int, @FnBit bit output AS
declare @SQL varchar(8000)
set @SQL = ' if dbo.' + @FnNameYN + ' (' + convert(varchar(31),@InvLineID) + ')) = 1 set @FnBit = 1 else set @FnBit = 0'
exec (@SQL) GO
Obviously; @FnBit is not defined in @SQL so that execution will not work. Server: Msg 137, Level 15, State 1, Line 4 Must declare the variable '@FnBit'. Server: Msg 137, Level 15, State 1, Line 5 Must declare the variable '@FnBit'.
So; is there a way to get a value out of a Dynamic SQL piece of code and get that value INTO my OUTPUT variable?
My many thanks to anyone who can solve this riddle for me. Thank You!
Sigh: For now, it looks like I'll have a huge string of "IF" statements for each business rule function, as follows: Hopefully a better solution comes to light.
------ Vertical Build1 - Std Vanes ----------- if @FnNameYN = 'fnb_YN_B1_14' BEGIN if dbo.fnb_YN_B1_14 (convert(varchar(31),@InvLineID) ) = 1 set @FnBit = 1 else set @FnBit = 0 END
------ Vertical Build1 - Scissor Vanes ----------- if @FnNameYN = 'fnb_YN_B1_15' BEGIN if dbo.fnb_YN_B1_15 (convert(varchar(31),@InvLineID) ) = 1 set @FnBit = 1 else set @FnBit = 0 END . . . etc.
I am building an SSIS package that is hitting about 50 remote servers. I have a for each loop container that i am using to build the list of servers to run.
The problem is...sometimes networks go down, sometimes connections time out and this causes my entire package to fail. I inserted a task that will run select @@ServerName on the remote server inside the loop. My thought was, if this returns an error I could ignore it and move on to the next server in the list and log somewhere that server x threw an error. Logging is easy, the problem is, how do I then tell it to move on to the next server in the loop?
If anyone has any suggestions on how better to do this, I am open for alternatives...
I've looked up Books Online on Dynamic Cursor/ Dynamic SQL Statement.
Using the examples given in Books Online returns compilation errors. See below.
Does anyone know how to use Dynamic Cursor/ Dynamic SQL Statement?
James
-- SQL ---------------
EXEC SQL BEGIN DECLARE SECTION; char szCommand[] = "SELECT au_fname FROM authors WHERE au_lname = ?"; char szLastName[] = "White"; char szFirstName[30]; EXEC SQL END DECLARE SECTION;
EXEC SQL DECLARE author_cursor CURSOR FOR select_statement;
EXEC SQL PREPARE select_statement FROM :szCommand;
EXEC SQL OPEN author_cursor USING :szLastName; EXEC SQL FETCH author_cursor INTO :szFirstName;
--Error-------------------- Server: Msg 170, Level 15, State 1, Line 23 Line 23: Incorrect syntax near ';'. Server: Msg 1038, Level 15, State 1, Line 24 Cannot use empty object or column names. Use a single space if necessary. Server: Msg 1038, Level 15, State 1, Line 25 Cannot use empty object or column names. Use a single space if necessary. Server: Msg 170, Level 15, State 1, Line 27 Line 27: Incorrect syntax near ';'. Server: Msg 170, Level 15, State 1, Line 30 Line 30: Incorrect syntax near 'select_statement'. Server: Msg 170, Level 15, State 1, Line 33 Line 33: Incorrect syntax near 'select_statement'. Server: Msg 102, Level 15, State 1, Line 35 Incorrect syntax near 'author_cursor'. Server: Msg 170, Level 15, State 1, Line 36 Line 36: Incorrect syntax near ':'.
I have a requirment which i have partly accomplished , but could not get through completely
i have a file which comes in a standard format ending with date and seq number ,
suppose , the file name is abc_yyyymmdd_01 , for first copy , if it is copied more then once the sequence number changes to 02 and 03 and keep going on .
then i need to transform those in to new file comma delimited destination file with a name abc_yyyymmdd,txt and others counting file counting record abc_count_yyyymmdd.txt. and move it to a designated folder. and the source file is then moved to archived folder
what i have taken apprach is
script task select source file --------------------> data flow task------------------------------------------> script task to destination file
dataflow task -------------------------> does count and copy in delimited format
what is happening here is i can accomlish a regular source file convert it to delimited destination file --------> and move it to destination folder with script task .
but cannot work the dynamic pick of a source file.
please advise with your comments or solution you have
Is there anyway to dynamically change the Sql Server Destination? Let's imagine i want the data to go to a table based on a specific parameter like year for example...
Imagine tables like table1_2005, table1_2006 and i want to dinamically change the SQL Server Destination so it would insert 2005 or 2006 and so on....
I can't seem to find that option... It was really a good idea for microsoft to implement Expressions in such components... Dynamics it's all about it :)
Scenario/Requirements: We have different SQL servers for each of our environments - for arguments sake let's just stick with Dev, Test and Prod (though in reality there are many more) and we want to isolate the environments - i.e. Dev, Test and definitely Prod should be able to stand-alone. We want to be able to design a package once and then just migrate these through each environment and just reconfigure it externally to operate within the environment (so it made sense to use package configuration for this).Package configuration shall load things like server connection strings for that environment, and other variables specific to that environment with the intention that any package can use the same configuration for the target environment (and of course, allowing ease of migration). The reason why we chose SQL Server to store the package configuration is because there are sensitive information used in our queries required to be stored and loaded between each environment and by using SQL Server we can manage all the security in one place (XML would require filesystem security which is kind of out of our DBA hands, as would other approaches). We would setup the configuration table to sit in the same place per server much like how the XML alternative would have worked. Aim and Problem:
Be able to change the SQL Server where the package configuration is loaded from after the package has been designed (without it becoming a maintenance nightmare).However, it seems that DTEXEC will always load the package configuration before any parameters via the command-line are passed into the package (thus we can't change where it looks for the package configuration).
Options explored and discounted: Initially (before we discovered the issue with the order which package configuration was loaded), we thought we could just specify the connection string for the package configuration from the command line and it would thus load the appropriate variables from that connection. Instead we found that by the time the correct connection string from the command-line was put in place, the package configuration has already been loaded and thus ignores it. Indirect Configuration (i.e. via environment var) - for SQL Server configuration this allows you to vary the connection object (not the connection string), the table and the configuration filter.The problem with this is that if we chose to vary the later two, then once the package is migrated to Prod it would load the package configuration from the original connection specified in the package (i.e. Dev since that's where the package is originally designed to work in), which we can't accept this since Prod should be able to work without connecting to any other server.If we vary the connection object, then we need to define a connection object to each different server and that defeats the purpose of the package not knowing which environment it's supposed to operate in till run-time (and this would break if we add new environments or change the server that hosts that environment). Any ideas anyone? All we can come up with now is wait for MS add a new option for the SSIS package to allow the package configuration to be loaded after the command-line parameters are passed into the package (or provide some kind of SSIS task that reloads the package configuration we could add into the design of the package before it arrives at operations that rely on our environment specific settings).Thanks in advanced,Eric.
set @x1 = (select DRfieldname from tblJournalType where journaltypeid = 2 set @SQLstring = 'select ' + @x1 + ' from tblAssettype where assettypeid = 10' set @x2 = EXEC (@SQLstring)
The last line above is where I am getting the error. Is this possible to do this?
I have a person who just recomended to a customer to use Fixed instead of Dynamic for the SQL Server Memory setting informing me that I was wrong for setting it to use Dynamic.
Well I tried to explain that why would you want to give away memory if you do not need to, he just answered that I was wrong, any help in proving me wrong or him wrong?
Which way is the correct way. I was told by a very bright person with a strong background in the developement of SQL that when it was written it was done so with the word "fixed" memory size was done in lower case just as a reminder that you can but should never use "fixed" that you should always use Dynamic (which by the way does use a capitol "D"...)
Just wondering...Thanks for the help guys...
This is the personal edition running on the XP Pro platform for use in a Point-of-Sale enviorment with 6 other computers connecting to hte SQL server on the one back of house computer which is running 4mb of memory.
I told them that the minimum should be at zero and the max is set to half....
I am trying to create an ssis package with dynamic csv file as output. and out format contains query output.
sample file name:
Unique identifier + query output + systemdate();
The expression is looking like this.
@[User::FilePath] + @[User::FileName] + ".CSV"
-- user filepath is a variable from ssis package. File name is the output from SQL query. using script task i have assigned the values to @[User::FileName] .
When I debugged the script task the value getting properly but same variable am using for Flafile destination. but its not working.
When I installed VS 2005, it installed the default version of SQL Server 2005 Express that ships with Visual Studio 2005 installer media.
How can apply SQL Server 2005 Express SP1 to update this existing instance?
Currently, if I run this query:
SELECT @@version
I get the following:
Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86) Oct 14 2005 00:33:37 Copyright (c) 1988-2005 Microsoft Corporation Express Edition on Windows NT 5.1 (Build 2600: Service Pack 2)
After applying SP1, I should get 9.00.2047.00.
Should I just go to this link and download & install the SQL Server 2005 Express Edition SP1:
Hello, I have a datagrid which is populated with data from an MS SQL server database. When I run an update query it always throws an exception - what is the most likely cause for this given that I am using the code below: 1 public void DataGrid_Update(Object sender, DataGridCommandEventArgs e) 2 { 3 String update = "UPDATE Fruit SET Product = @ID, Quantity = @Q, Price = @P, Total = @T where Product = @Id"; 4 5 SqlCommand command = new SqlCommand(update, conn); 6 7 command.Parameters.Add(new SqlParameter("@ID", SqlDbType.NVarChar, 50)); 8 command.Parameters.Add(new SqlParameter("@Q", SqlDbType.NVarChar, 50)); 9 command.Parameters.Add(new SqlParameter("@P", SqlDbType.NVarChar, 50)); 10 command.Parameters.Add(new SqlParameter("@T", SqlDbType.NVarChar, 50)); 11 command.Parameters["@ID"].Value = DataGrid.DataKeys[(int)e.Item.ItemIndex]; 12 command.Connection.Open(); 13 14 try 15 { 16 command.ExecuteNonQuery(); 17 Message.InnerHtml = "Update complete!" + update; 18 DataGrid.EditItemIndex = -1; 19 } 20 catch (SqlException exc) 21 { 22 Message.InnerHtml = "Update error."; 23 } 24 25 command.Connection.Close(); 26 27 BindGrid(); 28 } All of the row types in MS SQL server are set to nvarchar(50) - as I thought this would eliminate any inconsistencies in types. Thanks anyone
I am trying to pivot some data as you would normally however I am trying to also group the pivot into three sub column groups too.
Basically the scenario is that I have three sub groups Budget, Person, RenewalDate for each Service (Service being the pivot point). So for each unique service I want to display the budget person and renewal date for each service by company.
I have created two tables to illustrate the base data and the required output.
How to do this dynamically because the number of Services is unknown, i.e. it could be 4 Services or 20, each with three sub columns, budget, person and renewal date.
Please find code below. It should be quite self explanatory as to what I am trying to do.
IMPORTANT:
1. I really need it to be dynamic 2. the Services are not standardised names, they are numbered for illustration purposes only, they vary in naming convention.
create table #BaseData ( Company nvarchar(100), Person nvarchar(50), [Service] nvarchar(100), Budget int, RenewalDate datetime )
1. What is the best practice for partitioning (on date column)
2. The project on which i am working correctly have a case where in i get the update of my status flag after few days (Say 15 - 30) in that case if my data got into partition table how to update and how to search which partition has my data
3. Is creating partition occupies more disk space?
I am trying to select data from table that have YYMM as table names, they are formatted table1410,table1411, table1412. I am trying to format it like this
declare @tablename60 varchar(50) = 'table' + SUBSTRING(CAST(DATEPART(YY,dateadd(yy, -1, getdate())) as varchar(4)),3,4) + SUBSTRING(CAST(DATEPART(MM,dateadd(mm, -1, getdate())) as varchar(2)),1,2)
But this is hard coding the YYMM, and I would like to have it pull 30,60,90 days fromthe first of the current month. I am having a bit of trouble formatting, how to accomplish this.