[Forum FAQ] How do I have Invoke-SqlCmd return a date value without adding time

Introduction
A select statement executed from Invoke-SqlCmd returns a value from a Date column, the value has "12:00:00 AM" appended.  The same select statement executed within SQL Server Management Studio displays the date properly without any time formatting.
Sample data is as follows:
How to have Invoke-SqlCmd return Date values without adding time for multiple Date type columns and pipe the output into CSV file?
Solution
In SQL Server 2012 or onwards, use the FORMAT() function to convert datetime values to date format when executing query from Invoke-SqlCmd. In earlier versions such as SQL Server 2008 R2, use the traditional CONVERT() function to format datetime values to
different date formats(yyyy.mm.dd, mm/dd/yyyy, etc) when executing query from Invoke-SqlCmd. Then pipe the output of SQL query result into CSV file by specifying export-csv parameter. An example is as follows.
Create a table named “Test_invokesqlcmd” that contains Date type columns in SQL Server.
USE Test
Go
CREATE TABLE [dbo].[Test_invokesqlcmd](
    [id] [int] NOT NULL,
    [name] [varchar](20) NULL,
    [test1] [date] NULL,
    [test2] [date] NULL
) ON [PRIMARY]
GO
insert into [dbo].[Test_invokesqlcmd]
values(1,'David','2014-10-15','2015-01-07'),(2,'Jane','2011-08-05','2012-11-7'),(3,'Crystal','2013-09-15','2010-02-24')
Define a query string, execute it from Invoke-SqlCmd and save the query result to a CSV file.
Scripts for SQL Server 2012:
$query1 = @"
    use Test;
    SELECT FORMAT(test1,'d') as newtest1, FORMAT(test2,'d') as newtest2 from dbo.Test_invokesqlcmd
write-host $query1
Invoke-Sqlcmd -Query $query1 -ServerInstance localhost | export-csv -notypeinformation -path c:\Files\test.csv
Scripts for SQL Server 2008 R2:
$query2 = @"
    Use Test;
    SELECT CONVERT(varchar, test1, 102) as newtest1,CONVERT(varchar, test2, 102) as newtest2
    FROM dbo. Test_invokesqlcmd
write-host $query2
Invoke-Sqlcmd -Query $query2 -ServerInstance localhost | export-csv -notypeinformation -path c:\Files\test.csv
Check the results in SQL Server PowerShell window and csv file.
SQL Server 2012:
SQL Server 2008 R2:
Reference
Using the Invoke-Sqlcmd cmdlet
SQL Server Functions that helps to convert date and time values to and from string literals and other date and time formats
Applies to
SQL Server 2014
SQL Server 2012
SQL Server 2008 R2
SQL Server 2008
Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

Cross posted. More appropriate in JSF forum so continue conversation there.
http://forum.java.sun.com/thread.jspa?threadID=717292&messageID=4142615#4142615

Similar Messages

  • [Forum FAQ] How do I send multiple rows returned by Execute SQL Task as Email content in SQL Server Integration Services?

    Question:
    There is a scenario that users want to send multiple rows returned by Execute SQL Task as Email content to send to someone. With Execute SQL Task, the Full result set is used when the query returns multiple rows, it must map to a variable of the Object data
    type, then the return result is a rowset object, so we cannot directly send the result variable as Email content. Is there a way that we can extract the table row values that are stored in the Object variable as Email content to send to someone?
    Answer:
    To achieve this requirement, we can use a Foreach Loop container to extract the table row values that are stored in the Object variable into package variables, then use a Script Task to write the data stored in packages variables to a variable, and then set
    the variable as MessageSource in the Send Mail Task. 
    Add four variables in the package as below:
    Double-click the Execute SQL Task to open the Execute SQL Task Editor, then change the ResultSet property to “Full result set”. Assuming that the SQL Statement like below:
    SELECT   Category, CntRecords
    FROM         [table_name]
    In the Result Set pane, add a result like below (please note that we must use 0 as the result set name when the result set type is Full result set):
    Drag a Foreach Loop Container connects to the Execute SQL Task. 
    Double-click the Foreach Loop Container to open the Foreach Loop Editor, in the Collection tab, change the Enumerator to Foreach ADO Enumerator, then select User:result as ADO object source variable.
    Click the Variable Mappings pane, add two Variables as below:
    Drag a Script Task within the Foreach Loop Container.
    The C# code that can be used only in SSIS 2008 and above in Script Task as below:
    public void Main()
       // TODO: Add your code here
                Variables varCollection = null;
                string message = string.Empty;
                Dts.VariableDispenser.LockForWrite("User::Message");
                Dts.VariableDispenser.LockForWrite("User::Category");
                Dts.VariableDispenser.LockForWrite("User::CntRecords");     
                Dts.VariableDispenser.GetVariables(ref varCollection);
                //Format the query result with tab delimiters
                message = string.Format("{0}\t{1}\n",
                                            varCollection["User::Category"].Value,
                                            varCollection["User::CntRecords"].Value
               varCollection["User::Message"].Value = varCollection["User::Message"].Value + message;   
               Dts.TaskResult = (int)ScriptResults.Success;
    The VB code that can be used only in SSIS 2005 and above in Script Task as below, please note that in SSIS 2005, we should
    change PrecompileScriptIntoBinaryCode property to False and Run64BitRuntime property to False
    Public Sub Main()
            ' Add your code here
            Dim varCollection As Variables = Nothing
            Dim message As String = String.Empty
            Dts.VariableDispenser.LockForWrite("User::Message")
            Dts.VariableDispenser.LockForWrite("User::Category")
            Dts.VariableDispenser.LockForWrite("User::CntRecords")
            Dts.VariableDispenser.GetVariables(varCollection)
            'Format the query result with tab delimiters
            message = String.Format("{0}" & vbTab & "{1}" & vbLf, varCollection("User::Category").Value, varCollection("User::CntRecords").Value)
            varCollection("User::Message").Value = DirectCast(varCollection("User::Message").Value,String) + message
            Dts.TaskResult = ScriptResults.Success
    End Sub
    Drag Send Mail Task to Control Flow pane and connect it to Foreach Loop Container.
    Double-click the Send Mail Task to specify the appropriate settings, then in the Expressions tab, use the Message variable as the MessageSource Property as below:
    The final design surface like below:
    References:
    Result Sets in the Execute SQL Task
    Applies to:
    Integration Services 2005
    Integration Services 2008
    Integration Services 2008 R2
    Integration Services 2012
    Integration Services 2014
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Thanks,
    Is this a supported scenario, or does it use unsupported features?
    For example, can we call exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='b64ce7ec-d598-45cd-bbc2-ea202e0c129d'
    in a supported way?
    Thanks! Josh

  • After a person submits a form, how can I have their screen return to my company's webpage?

    After a person submits a form, how can I have their screen return to my company's webpage?

    Setup a Redirect URL: http://forums.adobe.com/thread/869660

  • How come I have to off my Cellular Data for my Wi-Fi to work??

    How come I have to off my Cellular Data for my Wi-Fi to work??

    Off is off.
    If you want the alrm to go off, the iphone must be on.  It will be in sleep mode which saves battery.
    The blackberry was simply on standby mode, not off.  If it was off then the alrrm would not go off either.
    Feel free to leave feedback for Apple.  Let them know you want a stand by feature

  • Hello - how do I have more than one app window open at a time on OS X 10.9.1

    Hello - how do I have more than one app window open at a time on OS X 10.9.1?  I do not want to hold the option key to have multiple apps open on my screen.  Thanks.

    Barney-15E
    Finder enhnacements installed? = no.  I did a reinstall of Mavericks, not a full clean install = no help. Searched for "single-app mode" in Spotlight and the web, no luck.
    With Safari open on screen, from dock, opened iTunes and Safari does not show on screen.  Open Word from doc and iTunes is not on screen. 
    Attached some screen shots if these help.

  • HT201209 How can I create an apple ID for my daughter, without adding a credit card to the account?

    How can I create an apple ID for my daughter, without adding a credit card to the account? I have tried to purchase a gift card online, but it just credits it to my account; I cannot use it to credit her new account therefore I cannot create that account.

    There are intructions on this page for how to create a new account without giving credit card details : http://support.apple.com/kb/HT2534
    e.g. log out of your account, find a free a free app in the store, click on its free 'price' :
    click on 'create Apple id' on the popup :
    Agree to the terms and fill in the details, and you should get 'none' on the payments screen.

  • How can I do to acquire and save date in the same time and in the same file when I run continual my VI without interrupti​on.

    I've attached a VI that I am using to acquire amplitude from Spectrum analyzerse. I tried to connect amplitude ouput to the VI Write Characters To File.vi and Write to Spreadsheet File.vi. Unfortunately when I run continual this VI without interruption, labview ask me many time to enter a new file name to save a new value.
    So, How can I do to aquire and save date in the same time and in the same file when I run continual my VI for example during 10 min.
    Thank you in advance.
    Regards,
    Attachments:
    HP8563E_Query_Amplitude.vi ‏37 KB

    Hi,
    Your VI does work perfectly. Unfortunately this not what I want to do. I've made error in my last comment. I am so sorry for this.
    So I explain to you again what I want to do exactly. I want to acquire amplitude along road by my vehicle. I want to use wheel signal coming from vehicle to measure distance along road. Then I acquire 1 amplitude each 60 inches from spectrum analyzer.
    I acquire from PC parallel port a coded wheel signal coming from vehicle (each period of the signal corresponds to 12 Inches). Figure attached shows the numeric signal coming from vehicle, and the corresponding values “120” and “88” that I can read from In Port vi.
    So I want to acquire 1 time amplitude from spectrum analyser each 5
    period of the signal that I am acquiring from parallel port.
    So fist I have to find how can I count the number of period from reading the values “120” and “88” that I am acquiring from In Port (I don’t know the way to count a number of period from reading values “120” and “88”).
    Here is a new algorithm.
    1) i=0 (counter: number of period)
    2) I read value from In Port
    3) If I acquire a period
    i= i+1 (another period)
    4) If i is multiple of 5 (If I read 5 period)
    acquire 1 time amplitude and write to the same
    file this amplitude and the corresponding distance
    Distance = 12*i). Remember each period of signal
    Corresponds to 12 Inches).i has to take these
    values: 5,10,15,20,25,35,40,45,50,55,60............
    5) Back to 2 if not stop.
    Thank you very much for helping me.
    Regards,
    Attachments:
    Acquire_Amplitude_00.vi ‏59 KB
    Figure_Algorithm.doc ‏26 KB

  • [Forum FAQ] How to install and configure Windows Server Essentials Experience role on Windows Server 2012 R2 Standard via PowerShell locally and remotely

    As we all know,
    the Windows Server Essentials Experience role is available in Windows Server 2012 R2 Standard and Windows Server 2012 R2 Datacenter. We can add the Windows Server
    Essentials Experience role in Server Manager or via Windows PowerShell.
    In this article, we introduce the steps to install and configure Windows
    Server Essentials Experience role on Windows Server 2012 R2 Standard via PowerShell locally and remotely. For better analyze, we divide this article into two parts.
    Before installing the Windows Server Essentials Experience Role, please use
    Get-WindowsFeature
    PowerShell cmdlet to ensure the Windows Server Essentials Experience (ServerEssentialsRole) is available. (Figure 1)
    Figure 1.
    Part 1: Install Windows Server Essentials Experience role locally
    Add Windows Server Essentials Experience role
    Run Windows PowerShell as administrator, then type
    Add-WindowsFeature ServerEssentialsRole cmdlet to install Windows Server Essentials Experience role. (Figure 2)
    Figure 2.
    Note: It is necessary to configure Windows Server Essentials Experience (Post-deployment Configuration). Otherwise, you will encounter following issue when opening Dashboard.
    (Figure 3)
    Figure 3.
      2. Configure Windows Server Essentials Experience role
    (1)  In an existing domain environment
    Firstly, please join the Windows Server 2012 R2 Standard computer to the existing domain through the path:
    Control Panel\System\Change Settings\”Change…”\Member of. (Figure 4)
    Figure 4.
    After that, please install Windows Server Essentials Experience role as original description. After installation completed, please use the following command to configure Windows
    Server Essentials:
    Start-WssConfigurationService –Credential <Your Credential>
    Note: The type of
    Your Credential should be as: Domain-Name\Domain-User-Account.
    You must be a member of the Enterprise Admin group and Domain Admin group in Active Directory when using the command above to configure Windows Server Essentials. (Figure 5)
    Figure 5.
    Next, you can type the password for the domain account. (Figure 6)
    Figure 6.
    After setting the credential, please type “Y” to continue to configure Windows Server Essentials. (Figure 7)
    Figure 7.
    By the way, you can use
    Get-WssConfigurationStatus
    PowerShell cmdlet to
    get the status of the configuration of Windows Server Essentials. Specify the
    ShowProgress parameter to view a progress indicator. (Figure 8)
    Figure 8.
    (2) In a non-domain environment
    Open PowerShell (Run as Administrator) on the Windows Server 2012 R2 Standard and type following PowerShell cmdlets: (Figure 9)
    Start-WssConfigurationService -CompanyName "xxx" -DNSName "xxx" -NetBiosName "xxx" -ComputerName "xxx” –NewAdminCredential $cred
    Figure 9.
    After you type the commands above and click Enter, you can create a new administrator credential. (Figure 10)
    After creating the new administrator credential, please type “Y” to continue to configure Windows Server Essentials. (Figure 11)
    After a reboot, all the configurations will be completed and you can open the Windows Server Essentials Dashboard without any errors. (Figure 12)
    Figure 12.
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Part 2: Install and configure Windows Server Essentials Experience role remotely
    In an existing domain environment
    In an existing domain environment, please use following command to provide credential and then add Server Essentials Role: (Figure 13)
    Add-WindowsFeature -Name ServerEssentialsRole
    -ComputerName xxx -Credential DomainName\DomainAccount
    Figure 13.
    After you enter the credential, it will start install Windows Server Essentials role on your computer. (Figure 14)
    Figure 14.
    After the installation completes, it will return the result as below:
    Figure 15.
    Next, please use the
    Enter-PSSession
    cmdlet and provide the correct credential to start an interactive session with a remote computer. You can use the commands below:
    Enter-PSSession –ComputerName
    xxx –Credential DomainName\DomainAccount (Figure 16)
    Figure 16.
    Then, please configure Server Essentials Role via
    Add-WssConfigurationService cmdlet and it also needs to provide correct credential. (Figure 17)
    Figure 17.
    After your credential is accepted, it will update and prepare your server. (Figure 18)
    Figure 18.
    After that, please type “Y” to continue to configure Windows Server Essentials. (Figure 19)
    Figure 19.
    2. In a non-domain environment
    In my test environment, I set up two computers running Windows Server 2012 R2 Standard and use Server1 as a target computer. The IP addresses for the two computers are as
    below:
    Sevrer1: 192.168.1.54
    Server2: 192.168.1.53
    Run
    Enable-PSRemoting –Force on Server1. (Figure 20)
    Figure 20.
    Since there is no existing domain, it is necessary to add the target computer (Server1) to a TrustedHosts list (maintained by WinRM) on Server 2. We can use following command
    to
    add the TrustedHosts entry:
    Set-Item WSMan:\localhost\Client\TrustedHosts IP-Address
    (Figure 21)
    Figure 21.
    Next, we can use
    Enter-PSSession
    cmdlet and provide the correct credential to start an interactive session with the remote computer. (Figure 22)
    Figure 22.
    After that, you can install Windows Server Essentials Experience Role remotely via Add-WindowsFeature ServerEssentialsRole cmdlet. (Figure 23)
    Figure 23.
    From figure 24, we can see that the installation is completed.
    Figure 24.
    Then you can use
    Start-WssConfigurationService cmdlet to configure Essentials Role and follow the steps in the first part (configure Windows Server Essentials Experience in a non-domain environment) as the steps would be the same.
    The figure below shows the status of Windows Server Essentials.
    Figure
    25.
    Finally, we have successfully configured Windows Server Essentials on Server1. (Figure 26)
    Figure 26.
    More information:
    [Forum
    FAQ] Introduce Windows Powershell Remoting
    Windows Server Essentials Setup Cmdlets
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

  • [Forum FAQ] How to convert data of date time's type stored in database to display Time Zone based on different territories?

    Introduction:
    There is a date’s type field in the database. When using the field in the report, clients want to convert the field’s values based on own Time Zone to show the date field.
    Workaround:
    Currently, Reporting Services doesn’t provide the function that can get the Time Zone of a client machine. To work around the issue, you need to add a custom code in the report to convert Time Zone and create a parameter through which the client users can
    select his/her Time Zone, and then pass the parameter value to the custom function. Please see the details as follows:
    1. Click the Report, select Report Properties and add the custom code as the screenshot shown:
    Custom code:
    Shared Function FromUTC (ByVal d As Date, ByVal tz As String) As Date
    Return (TimeZoneInfo.ConvertTimeBySystemTimeZoneId(d, TimeZoneInfo.Utc.Id, tz))
    End Function
    2. Create a parameter named TimeZone (you can name the parameter according to your requirement), select Available value and click Specify values.
    Label                                                               
    Value
    China Standard Time                                        
    China Standard Time
    Central European Time Zone                              Central European Time Zone
    India Time Zone                                               
    India Time Zone
    United States of America Time zones                   United States of America Time zones
    3. Call the custom code and type the expression to convert the Time Zone as follows:
    =Code.FromUTC(Fields!UTCDateFromDatabase.Value,Parameters!TimeZone.Value)
    Note: If you use the expression “=Code.FromUTC(Fields!UTCDateFromDatabase.Value,TimeZone.CurrentTimeZone.StandardName)”, it cannot achieve the goal because TimeZone.CurrentTimeZone.StandardName gets the TimeZone of Report Server side rather than Client side.
    More information:
    TimeZone Class
    http://msdn.microsoft.com/en-us/library/system.timezone(v=vs.110).aspx
    Applies to
    Microsoft SQL Server 2005
    Microsoft SQL Server 2008
    Microsoft SQL Server 2008 R2
    Microsoft SQL Server 2012

    Hello,
    Please read the answer provided by Kalman on the following thread:
    http://social.technet.microsoft.com/Forums/es-ES/446df85a-7ad8-4891-8748-478a26350c5c/how-to-compare-tables-in-two-different-servers-while-one-of-the-server-name-has-a-?forum=transactsql
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • AnyGantt: How to set different bar color depending on data value.

    Need to have different colors for bars in a gantt resource chart.
    The color depends on certain data value not included in the visible part of the chart, so it must be provided 'extra' for the chart in some way without beeing visible.
    Have studied some examples but cannot figure out the mechanism for this, and the procedure to implement it.
    Any ideas?
    Apex 4.2.2
    Regards
    Per.

    Hi Per,
    You mention "+Among the samples I can see that it has been implemented, but not how.+" - in the Information region below the chart that Tony referred to (https://apex.oracle.com/pls/apex/f?p=36648:50) that I've stated the following:
    "The elements of the Timeline region have been customized via the Chart Attributes page, using the following settings: *Custom Colors*: #000000,#00FF00,#0033FF"
    So that's how I applied custom colours to that particular chart. However, that declarative option won't meet your requirements, where the colours you wish to apply are dependent on data not included in the chart series query. You mention "+Now, if I add another column to the statement I get a yellow error message telling that the statement is not valid.+". It is not possible to simply add an additional column to the chart series query. Each supported chart type expects the associated chart series query to use specific syntax - see About Creating SQL Queries for Charts in Chapter 10 of the APEX User's Guide, http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35125/bldapp_chrt.htm#BCEIJJID.
    So to answer your question "+How to add the new value if not providing another column to the graph?+", if you wish to customise your chart to that extent, then you will need to use custom XML. Depending on what exactly you're trying to achieve, this may require the generation of custom data for your chart. If you edit your chart, and take a look at the Custom XML region, you'll notice a substitution string, #DATA#, towards the end of the XML. When a chart is rendered, we use the chart series query to generate the necessary XML to represent the data on the chart, replacing the string #DATA# with the actual XML. The format of the data XML generated for gantt charts uses a bar style called "defaultStyle", and this handles the default appearance of the bars in the timeline region e.g.
    <period resource_id="1" start="2009.03.21 00.00.00" end="2009.09.21 00.00.00" style="defaultStyle"/>You'll see that the 'style="defaultStyle" ' attribute of the data corresponds to a segment of XML outlining what that style is e.g.
    <period_style name="defaultStyle">Now take a look at the Bar Style in Resource Project example in the AnyChart online documentation http://www.anychart.com/products/anygantt/docs/users-guide/bar-style.html#bar-style-application-resource-project. In that particular example, a number of different bar styles are used i.e.
    <periods>
      <period resource_id="server_1" start="2008.07.07" end="2008.07.8" style="Working" />
      <period resource_id="server_1" start="2008.07.8" end="2008.07.12" style="Maintance" />If you need to add a different bar style to particular rows of data on your chart, then you'll need to add new bar style XML for each colour you wish to use in the Custom XML on the Chart Attributes page, and then you'll also need to generate the data XML yourself, applying the necessary bar style to the relevant row of data. I've got an example of how custom data can be generated for a Resource Gantt here e.g. https://apex.oracle.com/pls/apex/f?p=36648:73 but keep in mind that particular example doesn't demo adding different styles to the data...but it can certainly give you an idea of what's entailed in the generation of custom data for your chart.
    I hope this helps.
    Regards,
    Hilary

  • [Forum FAQ] How do I send an email to users when the data in the report have been changed in Reporting Services?

    Introduction
    There is a scenario that the data in the report changes infrequently, so the users want to be informed and get the most updated data once the data changes. By default, report server always run the report with the most recent data. Is there a way that we
    can subscribe the report, so that we can send an email to users when the data in the report has been changed?
    Solution
    To achieve this requirement, we can create a subscription for the report, then create a trigger in the table which including the report data. When this table has data insert, update or delete, it will be triggered and execute the subscription to send email
    to users.
    In the Report Manager, create a subscription for the report and make it only execute one time.
    When we create a subscription, a corresponding SQL Agent job will be created. Then we can use the query below to find out the job based on ScheduleId:
    -- List all SSRS subscriptions
    USE [ReportServer];  -- You may change the database name.
    GO 
    SELECT USR.UserName AS SubscriptionOwner
          ,SUB.ModifiedDate
          ,SUB.[Description]
          ,SUB.EventType
          ,SUB.DeliveryExtension
          ,SUB.LastStatus
          ,SUB.LastRunTime
          ,SCH.NextRunTime
          ,SCH.Name AS ScheduleName   
              ,RS.ScheduleId
          ,CAT.[Path] AS ReportPath
          ,CAT.[Description] AS ReportDescription
    FROM dbo.Subscriptions AS SUB
         INNER JOIN dbo.Users AS USR
             ON SUB.OwnerID = USR.UserID
         INNER JOIN dbo.[Catalog] AS CAT
             ON SUB.Report_OID = CAT.ItemID
         INNER JOIN dbo.ReportSchedule AS RS
             ON SUB.Report_OID = RS.ReportID
                AND SUB.SubscriptionID = RS.SubscriptionID
         INNER JOIN dbo.Schedule AS SCH
             ON RS.ScheduleID = SCH.ScheduleID
    ORDER BY USR.UserName
             ,SUB.ModifiedDate ;
    Create a trigger in the table which including the report data.
    CREATE TRIGGER reminder
    ON test.dbo.users
    AFTER INSERT, UPDATE, DELETE
    AS
    exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='b64ce7ec-d598-45cd-bbc2-ea202e0c129d'
    Please note that the command ‘exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='b64ce7ec-d598-45cd-bbc2-ea202e0c129d'’ is coming from the job properties. We can go to SQL Server Agent Jobs, right-click the corresponding job to open
    the Steps, copy the step command, and then paste it to the query.
    Then when the user table has data insert, update or delete, the trigger will be triggered and execute the subscription to send email to users.
    References:
    Subscriptions and Delivery (Reporting Services)
    Internal Working of SSRS Subscriptions
    SQL Server Agent
    Applies to:
    Reporting Services 2005
    Reporting Services 2008
    Reporting Services 2008 R2
    Reporting Services 2012
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Thanks,
    Is this a supported scenario, or does it use unsupported features?
    For example, can we call exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='b64ce7ec-d598-45cd-bbc2-ea202e0c129d'
    in a supported way?
    Thanks! Josh

  • [Forum FAQ] How to deploy applications remotely

    In some situations, we may need some ways to install applications remotely, here we summarize four general ways to deploy applications.
    1. Using PowerShell to install
    We can use the Win32_Product class to install Windows Installer packages, remotely or locally, so in this way, we can use powerShell command to invoke this function. For example, to install the NewPackage.msi package located in the network
    share \\AppServ\remote on the remote computer PC01, type the following command at the Windows PowerShell prompt:
    (Get-WMIObject -ComputerName PC01 -List | Where-Object -FilterScript {$_.Name -eq "Win32_Product"}).Install(\\AppSrv\remote\NewPackage.msi)
    In same method, we can use the following command to deploy .exe application:
    (Get-WMIObject -ComputerName PC01 -List | Where-Object -FilterScript {$_.Name -eq "Win32_Process"}).Create(\\AppSrv\remote\NewPackage.exe)
    Note: The applications should use Windows Installer technology.
    2. PsExec tool: one of sysinternals utilities
    PsExec's most powerful uses include launching interactive command-prompts on remote systems and remote-enabling tools like IpConfig that otherwise do not have the ability to show information about remote systems. So, we can use this feature to install our
    applications, in fact this is similar with PowerShell methods, the only difference is that PsExec is a comprehensive tool. Similarly, we can use the following command to achieve our goal:
    psexec \\PC01  cmd /c  "\\AppSrv\remote\NewPackage.msi" /quiet /norestart
    Note: we can also use PsExec tool to install Microsoft Update file (.msu)
    psexec \\PC01  -s -h -d wusa.exe  "\\AppSrv\remote\NewPackage.msu" /quiet /norestart
    3. Group Policy Software Installation
    In domain environment, this method is very useful to deploy our software. It only supports MSI package for deployment.
    We can choose assign a program to user or computer. If you assign the program to a user, it is installed when the user logs on to the computer. When the user first runs the program, the installation is completed. If you assign the program to a computer,
    it is installed when the computer starts, and it is available to all users who log on to the computer. When a user first runs the program, the installation is completed.
    You can get the installation information of group policy software installation in event viewer, including success or failure.
    4. System Center Configuration Manger
    The Microsoft System Center Configuration Manager software distribution feature provides a set of tools and resources that help you create and manage packages and advertisements used to distribute software to client resources within your enterprise. This
    is a comprehensive suit for deployment.
    How to Deploy Applications in Configuration Manager
    http://technet.microsoft.com/en-us/library/gg682082.aspx
    Summary:
    There are a lot of methods for software deployment, here just introduce some generic ways.
    Here is another important point of software deployment: Some applications do not use windows installer technology. 
    Applications that do not use Windows Installer technology may have application-specific methods for automated deployment. For example, a .exe file may be just a wrapper, it can be anything. To determine whether there is a method for deployment automation,
    check the documentation for the application or consult the application vendor's support system. In some cases, even if the application vendor did not specifically design the application for installation automation, the installer software manufacturer may have
    some techniques for automation.
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    In some situations, we may need some ways to install applications remotely, here we summarize four general ways to deploy applications.
    1. Using PowerShell to install
    We can use the Win32_Product class to install Windows Installer packages, remotely or locally, so in this way, we can use powerShell command to invoke this function. For example, to install the NewPackage.msi package located in the network
    share \\AppServ\remote on the remote computer PC01, type the following command at the Windows PowerShell prompt:
    (Get-WMIObject -ComputerName PC01 -List | Where-Object -FilterScript {$_.Name -eq "Win32_Product"}).Install(\\AppSrv\remote\NewPackage.msi)
    In same method, we can use the following command to deploy .exe application:
    (Get-WMIObject -ComputerName PC01 -List | Where-Object -FilterScript {$_.Name -eq "Win32_Process"}).Create(\\AppSrv\remote\NewPackage.exe)
    Note: The applications should use Windows Installer technology.
    2. PsExec tool: one of sysinternals utilities
    PsExec's most powerful uses include launching interactive command-prompts on remote systems and remote-enabling tools like IpConfig that otherwise do not have the ability to show information about remote systems. So, we can use this feature to install our
    applications, in fact this is similar with PowerShell methods, the only difference is that PsExec is a comprehensive tool. Similarly, we can use the following command to achieve our goal:
    psexec \\PC01  cmd /c  "\\AppSrv\remote\NewPackage.msi" /quiet /norestart
    Note: we can also use PsExec tool to install Microsoft Update file (.msu)
    psexec \\PC01  -s -h -d wusa.exe  "\\AppSrv\remote\NewPackage.msu" /quiet /norestart
    3. Group Policy Software Installation
    In domain environment, this method is very useful to deploy our software. It only supports MSI package for deployment.
    We can choose assign a program to user or computer. If you assign the program to a user, it is installed when the user logs on to the computer. When the user first runs the program, the installation is completed. If you assign the program to a computer,
    it is installed when the computer starts, and it is available to all users who log on to the computer. When a user first runs the program, the installation is completed.
    You can get the installation information of group policy software installation in event viewer, including success or failure.
    4. System Center Configuration Manger
    The Microsoft System Center Configuration Manager software distribution feature provides a set of tools and resources that help you create and manage packages and advertisements used to distribute software to client resources within your enterprise. This
    is a comprehensive suit for deployment.
    How to Deploy Applications in Configuration Manager
    http://technet.microsoft.com/en-us/library/gg682082.aspx
    Summary:
    There are a lot of methods for software deployment, here just introduce some generic ways.
    Here is another important point of software deployment: Some applications do not use windows installer technology. 
    Applications that do not use Windows Installer technology may have application-specific methods for automated deployment. For example, a .exe file may be just a wrapper, it can be anything. To determine whether there is a method for deployment automation,
    check the documentation for the application or consult the application vendor's support system. In some cases, even if the application vendor did not specifically design the application for installation automation, the installer software manufacturer may have
    some techniques for automation.
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

  • [Forum FAQ] How to use multiple field terminators in BULK INSERT or BCP command line

    Introduction
    Some people want to know if we can have multiple field terminators in BULK INSERT or BCP commands, and how to implement multiple field terminators in BULK INSERT or BCP commands.
    Solution
    For character data fields, optional terminating characters allow you to mark the end of each field in a data file with a field terminator, as well as the end of each row with a row terminator. If a terminator character occurs within the data, it is interpreted
    as a terminator, not as data, and the data after that character is interpreted and belongs to the next field or record. I have done a test, if you use BULK INSERT or BCP commands and set the multiple field terminators, you can refer to the following command.
    In Windows command line,
    bcp <Databasename.schema.tablename> out “<path>” –c –t –r –T
    For example, you can export data from the Department table with bcp command and use the comma and colon (,:) as one field terminator.
    bcp AdventureWorks.HumanResources.Department out C:\myDepartment.txt -c -t ,: -r \n –T
    The txt file as follows:
    However, if you want to bcp by using multiple field terminators the same as the following command, which will still use the last terminator defined by default.
    bcp AdventureWorks.HumanResources.Department in C:\myDepartment.txt -c -t , -r \n -t: –T
    The txt file as follows:
    When multiple field terminators means multiple fields, you use the below comma separated format,
    column1,,column2,,,column3
    In this occasion, you only separate 3 fields (column1, column2 and column3). In fact, after testing, there will be 6 fields here. That is the significance of a field terminator (comma in this case).
    Meanwhile, using BULK INSERT to import the data of the data file into the SQL table, if you specify terminator for BULK import, you can only set multiple characters as one terminator in the BULK INSERT statement.
    USE <testdatabase>;
    GO
    BULK INSERT <your table> FROM ‘<Path>’
     WITH (
    DATAFILETYPE = ' char/native/ widechar /widenative',
     FIELDTERMINATOR = ' field_terminator',
    For example, using BULK INSERT to import the data of C:\myDepartment.txt data file into the DepartmentTest table, the field terminator (,:) must be declared in the statement.
    In SQL Server Management Studio Query Editor:
    BULK INSERT AdventureWorks.HumanResources.DepartmentTest FROM ‘C:\myDepartment.txt’
     WITH (
    DATAFILETYPE = ‘char',
    FIELDTERMINATOR = ‘,:’,
    The new table contains like as follows:  
    We could not declare multiple field terminators (, and :) in the Query statement,  as the following format, a duplicate error will occur.
    In SQL Server Management Studio Query Editor:
    BULK INSERT AdventureWorks.HumanResources.DepartmentTest FROM ‘C:\myDepartment.txt’
     WITH (
    DATAFILETYPE = ‘char',
    FIELDTERMINATOR = ‘,’,
    FIELDTERMINATOR = ‘:’
    However, if you want to use a data file with fewer or more fields, we can implement via setting extra field length to 0 for fewer fields or omitting or skipping more fields during the bulk copy procedure.  
    More Information
    For more information about filed terminators, you can review the following article.
    http://technet.microsoft.com/en-us/library/aa196735(v=sql.80).aspx
    http://social.technet.microsoft.com/Forums/en-US/d2fa4b1e-3bd4-4379-bc30-389202a99ae2/multiple-field-terminators-in-bulk-insert-or-bcp?forum=sqlgetsta
    http://technet.microsoft.com/en-us/library/ms191485.aspx
    http://technet.microsoft.com/en-us/library/aa173858(v=sql.80).aspx
    http://technet.microsoft.com/en-us/library/aa173842(v=sql.80).aspx
    Applies to
    SQL Server 2012
    SQL Server 2008R2
    SQL Server 2005
    SQL Server 2000
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Thanks,
    Is this a supported scenario, or does it use unsupported features?
    For example, can we call exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='b64ce7ec-d598-45cd-bbc2-ea202e0c129d'
    in a supported way?
    Thanks! Josh

  • [Forum FAQ] How to display an image from Http response in Reporting Services?

    Question:
    There is a kind of scenario that users want to display an image which is from URL. In Reporting Services, if the URL points to an image file, we can directly display it by typing the URL in embedded image. However, some URLs are just sending Http requests
    to server side, then redirect to another position and the server will return the image. For these kind of URLs, Reporting Services can’t directly render the image from Http response.
    Answer:
    To achieve this goal, we can add custom code into the report. Pass the URL as argument into our custom function so that we can create HttpRequest and get the HttpResponse. Then we can use custom function to return the Bytes() from the HttpResponse and render
    it into an image in report.
    Ps: In Reporting Services, it only support drawing Bytes() array into image, so we need to have our custom function return Bytes array.
    Add the assembly and custom code into the report.
    Public shared Function GetImageFromByte(Byval URL as String) As byte() 
                    Dim photo as System.Drawing.Image 
             Dim Request As System.Net.HttpWebRequest 
           Dim Response As System.Net.HttpWebResponse 
                  Request = System.Net.WebRequest.Create(URL)         
                     Response = CType(Request.GetResponse, System.Net.WebResponse) 
                 If Request.HaveResponse Then  
                      If Response.StatusCode = Net.HttpStatusCode.OK Then                    
                           photo = System.Drawing.Image.FromStream(Response.GetResponseStream) 
                     End If 
                 End If 
                  Dim ms AS System.IO.MemoryStream = new System.IO.MemoryStream() 
                 photo.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg) 
                    Dim imagedata as byte()  
                    imagedata = ms.GetBuffer()  
                    return imagedata
    End Function
    Grant the permission for assemblies. 
    Go to: 
    C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\RSpreviewPolicy.config 
    C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\rssrvpolicy.config
    Give “FullTrust” for Report_Expressions_Default_Permissions.
    Insert an image into report. 
    Expression:
    =Code.GetImageFromByte("https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSrVwPoAtlcA2A3KaiAJi-XjS4icr1QUnKYr7uzpX3IL3g2GPisAQ")
    The Result looks below:
    Applies to:
    Reporting Services 2005
    Reporting Services 2008
    Reporting Services 2008 R2
    Reporting Services 2012
    Reporting Services 2014
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    >
    Hi, I'd like to display a dynamic image from the web inside a JLabel or any other swing component it could work in. I've been looking on the Swing tutorials and others forums, all I can have is that a JLabel can load an Icon object, defined by an image URL, but can this URL be like "http://xxxxx/image.jpg" somehow or can it only be a local image URL?>
    I do not know why you start talking about an image on the web then go on to show concerns about whether it will work for a 'local' URL.
    But perhaps this answer will cover the possibilities.
    So long as you can from an URL to the image, and the bytes are available for download (e.g. some web sites wrap a direct call to an image in HTML that embeds the image), the URL based icon constructors will successfully load it.
    It does not matter if that URL points to
    - a web site,
    - a local server ('localhost'),
    - an URL representation of a File on the local file system, or
    - it is inside a Jar file that is on the application's run-time classpath.
    How you go about forming a valid URL to a 'local resources' (or indeed what you regard as local resources) is another matter, depending on the form of the project, and how the resources are stored (see list above).
    Probably the main reason that examples use images at a hard coded URL on the net is that it makes an 'image example' self contained. As soon as we compile and run it, we can see the result. I have posted a few examples like that on these forums.
    Edit 1:
    BTW - Welcome to the Sun forums
    Edited by: AndrewThompson64 on Apr 21, 2009 12:15 PM

  • [Forum FAQ] How to find and replace text strings in the shapes in Excel using Windows PowerShell

    Windows PowerShell is a powerful command tool and we can use it for management and operations. In this article we introduce the detailed steps to use Windows PowerShell to find and replace test string in the
    shapes in Excel Object.
    Since the Excel.Application
    is available for representing the entire Microsoft Excel application, we can invoke the relevant Properties and Methods to help us to
    interact with Excel document.
    The figure below is an excel file:
    Figure 1.
    You can use the PowerShell script below to list the text in the shapes and replace the text string to “text”:
    $text = “text1”,”text2”,”text3”,”text3”
    $Excel 
    = New-Object -ComObject Excel.Application
    $Excel.visible = $true
    $Workbook 
    = $Excel.workbooks.open("d:\shape.xlsx")      
    #Open the excel file
    $Worksheet 
    = $Workbook.Worksheets.Item("shapes")       
    #Open the worksheet named "shapes"
    $shape = $Worksheet.Shapes      
    # Get all the shapes
    $i=0      
    # This number is used to replace the text in sequence as the variable “$text”
    Foreach ($sh in $shape){
    $sh.TextFrame.Characters().text  
    # Get the textbox in the shape
    $sh.TextFrame.Characters().text = 
    $text[$i++]       
    #Change the value of the textbox in the shape one by one
    $WorkBook.Save()              
    #Save workbook in excel
    $WorkBook.Close()             
    #Close workbook in excel
    [void]$excel.quit()           
    #Quit Excel
    Before invoking the methods and properties, we can use the cmdlet “Get-Member” to list the available methods.
    Besides, we can also find the documents about these methods and properties in MSDN:
    Workbook.Worksheets Property (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff835542(v=office.15).aspx
    Worksheet.Shapes Property:
    http://msdn.microsoft.com/en-us/library/office/ff821817(v=office.15).aspx
    Shape.TextFrame Property:
    http://msdn.microsoft.com/en-us/library/office/ff839162(v=office.15).aspx
    TextFrame.Characters Method (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff195027(v=office.15).aspx
    Characters.Text Property (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff838596(v=office.15).aspx
    After running the script above, we can see the changes in the figure below:
    Figure 2.
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Thank you for the information, but does this thread really need to be stuck to the top of the forum?
    If there must be a sticky, I'd rather see a link to a page on the wiki that has links to all of these ForumFAQ posts.
    EDIT: I see this is no longer stuck to the top of the forum, thank you.
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

Maybe you are looking for

  • Nokia 5800 will not turn on

    Hi Can anyone help me? I have had my Nokia 5800 for about 6 months and the battery life has always been fairly poor. Suddenly, though, over the last couple of days my phone would run out of charge within about 4 hours, without even being used. Today

  • I can't seem to power off

    After charging, my new iphone 4 sometimes gets funky. the screen locks and if I tap an icon, a fast voice identifies the icon and nothing else. I've tried to both shut down and reset to no avail. What am I doing wrong? btw...63 yeas old and first i P

  • 2.0 issues, next version?

    On purpose, until now I have NO apps loaded or running, it's a plain vanilla default original 8GB iPhone. After upgrading my iPhone to 2.0, I found the following main issues; 1) iPhone 1.1 Battery life is much shorter, perhaps 2 days at the most inst

  • Graph using static lov

    I am using a static lov which has a code and description. I select an entry from this lov and it's code is stored in a table. I now want to create a chart on the contents of this table, but need to translate the code stored in the table to the descri

  • Sticky Browser Request

    Dear All, We have a custom build application running on clustered WAS 6.0 with IHS as a proxy. We have come across a strange behaviour with our application. Our application has a authentication page and every user should supply password to access our