Quantcast
Channel: Forum Getting started with SQL Server
Viewing all 8979 articles
Browse latest View live

creating index with ONLINE=ON

$
0
0

Good Morning Experts,

There are no indexes on a table and I am creating index with ONLINE=ON option. Does this make any sense?


Kiran


Visual C++ version for SQL Server Management Studio 18.0 (preview 6)

$
0
0

May I ask if Microsoft Visual C++ 2017 Redistributable (x86) 14.12.25810 is included in downloading package of SQL Server Management Studio18.0 (preview 6)? Thank you

Date variable plus 1 day

$
0
0

Hi,

I have a date variable 'Date_End' formatted YYYY-MM-DD. 

What I need to do is add on 1 day to each record so if I had Date_end 2018-12-31 I want the new_end_date to show 2019-01-01

Thanks

Format Date

$
0
0

Hi,

How do I wrap a format into this logic please? I want the date to show 'MMM-yyyy'

dateadd(day,1,LD.END_DATE) as new_end_date

copy data

$
0
0

Database k1

table 1

column1 | column2 | column3

table 2

column 3

i use sql server 2008,  i want query to copy k1.table1.column3   into k1.table2.column3   data only with query


MUHAMMAD ANZAR E-mail : muhammadanzar@hotmail.com Mobile # :0092-3215096959

Way of accurately testing how SQL Server behaves Before and After TDE Enablement

$
0
0

Can I get some advice on below:

Our's is SQL Server 2014 SP2 GDR

We are with 3 Node AOAG Configuration (2 Primary Sites Synchronized & 1 Secondary BCP)

Now we are enabling TDE in this environment.

My question is about the performance testing and understand and test the behavior (Performance) of SQL Server pre & post TDE Enablement in this AOAG environment.

Please advice what are the basic steps and ways I should be thinking of.

If I need to utilize the SQL Profiler to understand the resource utilization , what are the major counter related to RAM , CPU , IO which I should be considering.

Kindly let me if there are any queries which are already used for this purpose.

Please also advice what are the things I need to keep in mind while enabling TDE on PROD Servers as priority.

Regards


Best Regards,SQLBoy


sql server 2012 installation error on windows server 2012 cluster

$
0
0
sql server 2012 installation error failed to get full path for folder c:\document and settings \administrator\appdada\local\appication data\appication data\appication data\appication data\appication data\appication data\appication data\appication data\appication data\appication data" path must be less then 248 character

whats the Difference between committed memory and physical mem in use in sqlserver

$
0
0

Hi MSDN,

Apart from total memory of my machine which is 8GB, what is the difference between these two columns(assuming second one is memory used by sqlserver I guess)? Any help is greatly appreciated.

Thanks.

FYI


Data losses after restore

$
0
0

Greetings to you all

I'm a newbie here and hope I am posting to the correct forum.  Please point me in the right direction if not

I have been a Windows server admin for over 25 years, and have had some dabbling's in SQL over the years, but am by no means a SQL admin.  I have backed up and restored DB's in the past so my current situation has me somewhat baffled.  I had thought that perhaps as a newbie I had done something to lose data through truncated logs or something by making bad decisions on options while performing my back up or the restore.

Here is where I am at.   We run Windows based systems and are leveraging Hyper-V for virtualization.   We have two physical hosts running which replicate between each other and use VEEAM as our backup technology.  We have been experiencing poor performance across the board on applications using SQL and having inherited the entire environment, thought I could do a better job of outfitting a better SQL system. Old system is a Windows 2008R2 server running SQL 2008 of which all installed to the only drive, C:

I spun up a new Windows Server 2012 R2 and installed a number of drives to hopefully increase the performance of the SQL services.   I have an OS drive, a TempDB drive, a Logs drive, a SQLDATA drive for the system DB's, a backup drive, an SSD dedicated to page file, and an application drive for the SQL application itself.

I migrated the DB's for all applications over to the new SQL system using the SSMS2008 on the old server to do a FULL backup, copied the .bak file across the network onto the new SQL2012 system, and then ran a restore.   This has worked well for all DB's to this point, but I've run into a mystery on this last go around.

In the interest of trying to be thorough, the application backing the issue at hand is Raiser's Edge.   It uses an application server in it's architecture which then talks to a SQL backend.  Client workstations connect, and get their configuration from the App server.  RE states that you need to use their native tools for moving a database, so using the RE management console, you need to "Attach" a database to the RE system.  You can't just edit a configuration or "point" the RE application at a SQL instance.  This "attach database" process in their management interface is doing a "Restore" in the background, and in the end, at least so I hoped, the application would end up repointed to a freshly restored copy of the DB on this new SQL2012 instance.

Well, it did.   It worked wonderfully and seemed quite responsive.  Unfortunately I received a call from the end users shortly afterwards telling me I had restored old data and that although it was Jan 18th 2019, the data showing in the application is only up to December 2018.   Somehow I'd gone from the RE application in use on the 117th and all days before, to having lost weeks of data. 

The database was actively used daily all of this month as it always is, so the transactions must be still on the database on the old SQL2008 system somewhere.    

Not sure where to turn while I await a SQL consultant to show up onsite if I can find one on short notice so I'm hopeful some of the kind souls here have a handle on what might be causing such woes

Mystified and exhausted

    Recursive Stored Procedure

    $
    0
    0

    Hi!

    I have some difficulty understanding recursive stored procedures. How does one execute a recursive SP, when it hasn't yet been created? eg. in this : https://www.guru99.com/sql-server-questions.html

    Also any practical real value examples will be great. 

    Thanks 

    Shav

    Database collation options are different than column collation options

    $
    0
    0

    Hi,

    SQL Server 2012

    I changed the collation of a database and now I try to manually change the collation of columns to be the same. But the options that I have in the column properties are different than those of the database... 

    For database I chose Romanian_100_CS_AS

    For columns I have 2 options like SQL_Romanian_CP1250_CS_AS.

    And even by using this collations, letters ș and ț wonțt work. Only ă, î and â work.

    Is this normal?

    Thank you, Alexandru

    Format my Table Output

    $
    0
    0

    Hi,

    I have the following code which outputs the standard table of 5 vertical columns

    select

    distinct(dbo.pk.job_number)as job_number,

    dbo.PK.Code,

    dbo.pk.name,

    FORMAT(DBO.DAD.INVOICE_DATE,'yyyy-MM')AS INVOICE_DATE,

    sum(dbo.DAD.draft_amount)as invoice

    from

    dbo.pk

    leftjoin dbo.dad

    on dbo.pk.job_number= dbo.dad.job

    groupby

    dbo.pk.name,

    dbo.PK.Code,

    dbo.pk.job_number,

    FORMAT(DBO.DAD.INVOICE_DATE,'yyyy-MM')

    How can I change the table output so that the Invoice_date variable essentially becomes a column so it's formatted something like this?

    Client_Codeclient_namejob_number2013-062013-092013-102013-112013-122014-012014-022014-03


    T-SQL Payment Apply in Order by Oldest Date

    $
    0
    0

    I'm trying to write a sql view to apply customer payments (oldest payment applied to oldest invoice in sequential order).  I'd like to apply the customer payments based on the oldest payment date being applied to the oldest invoice date until the payment no longer has any value remaining, then the next payment for that customer and so on.

    I can't change the table structure as it is tied to an ERP, payments and invoices are in the same table, payments are document type = 9 and invoices are document type 1.  There will be no negative numbers.  I can only apply up to the invoice/current amount (i.e. I cannot apply an amount that would cause a negative amount to be applied).

    here is some sample data:

    CREATE TABLE [dbo].[_ReceivablesDocuments](

    [Customer] [char](15) NOT NULL,
    [DocumentNbr] [char](21) NOT NULL,
    [PaymentCID] [char](21) NOT NULL,
    [DocumentType] [smallint] NOT NULL,
    [DocumentDate] [datetime] NOT NULL,
    [CurrentAmount] [numeric](19, 5) NOT NULL,
    [_ID] [int] IDENTITY(1,1) NOT NULL
    ) ON [PRIMARY]


    INSERT INTO _ReceivablesDocuments VALUES ('130308', 'OCK000000023830', '4328', 9, '12-05-2018', '43.60')
    INSERT INTO _ReceivablesDocuments VALUES ('130308', 'OCK000000023B2C', '4328', 9, '12-06-2018', '43.60')
    INSERT INTO _ReceivablesDocuments VALUES ('130666', 'OCC0000000295D7', '2232', 9, '12-20-2018', '226.10')
    INSERT INTO _ReceivablesDocuments VALUES ('130666', 'RCC00000003C9AD', '2232', 9, '01-18-2019', '103.35')
    INSERT INTO _ReceivablesDocuments VALUES ('131802', 'OCC00000002DF3B', '3701', 9, '01-02-2019', '200.00')
    INSERT INTO _ReceivablesDocuments VALUES ('131802', 'OCC00000002DF3D', '3701', 9, '01-02-2019', '30.00')
    INSERT INTO _ReceivablesDocuments VALUES ('131802', 'RCC00000002F7C3', '3701', 9, '01-02-2019', '17.65')

    INSERT INTO _ReceivablesDocuments VALUES ('130308', '0130308M181231', '', 1, '12-31-2018', 16.80000)
    INSERT INTO _ReceivablesDocuments VALUES ('130308', '130308-MIG-181031', '', 1, '10-31-2018', 16.80000)
    INSERT INTO _ReceivablesDocuments VALUES ('130308', '130308-MIG-181130', '', 1, '11-30-2018', 26.80000)
    INSERT INTO _ReceivablesDocuments VALUES ('130666', '0130666M181231', '', 1, '12-31-2018', 24.33000)
    INSERT INTO _ReceivablesDocuments VALUES ('131802', '131802-MIG-181130', '', 1, '11-30-2018', 17.65000)
    INSERT INTO _ReceivablesDocuments VALUES ('131802', '0131802M181231', '', 1, '12-31-2018', 131.83000)

    The results should look like this (based on above):

    CustomerPaymentDatePaymentNbrPaymentCID AvailableApplyAmount ApplyToDocumentNbrDocumentType InvoiceBalance InvoiceDate ApplyAmount 
    13030812/5/2018OCK000000023830      4328 $                                      43.60130308-MIG-181031    1 $                    16.8010/31/2018 $                  16.80
    13030812/5/2018OCK000000023830      4328 $                                      26.80130308-MIG-181130    1 $                    26.8011/30/2018 $                  26.80
    13030812/6/2018OCK000000023B2C      4328 $                                      43.600130308M1812311 $                    16.8012/31/2018 $                  16.80
    13066612/20/2018OCC0000000295D7      2232 $                                   226.100130666M181231       1 $                    24.3312/31/2018 $                  24.33
    1318021/2/2019OCC00000002DF3B      3701 $                                   200.00131802-MIG-1811301 $                    17.6511/30/2018 $               117.65
    1318021/2/2019OCC00000002DF3B      3701 $                                      82.350131802M181231       1 $                  131.8312/31/2018 $                  82.35
    1318021/2/2019OCC00000002DF3D3701 $                                      30.000131802M181231       1 $                    49.4812/31/2018 $                  30.00
    1318021/2/2019RCC00000002F7C33701 $                                      17.650131802M181231       1 $                    19.4812/31/2018 $                  17.65

    Here is the query I have but it doesn't quite work properly...

    WITH CTE AS (
    SELECT
    ROWNUM = ROW_NUMBER() OVER (Partition by CR.CUSTNMBR order by INV.DOCDATE, INV.DOCNUMBR),
    CR.CUSTNMBR as Customer_Nbr, CR.DOCDATE as Apply_Date
           , CR.DOCNUMBR as Source_Document_Nbr, CR.CHEKNMBR as Check_Nbr
           --, CR.CHEKBKID as Checkbook_Id
       , CR.CURTRXAM as Available_Apply_Amount
           --Apply Information
           , INV.DOCNUMBR as Apply_to_Document_Nbr, INV.CURTRXAM
           , INV.DOCDATE
              , CASE WHEN CR.CURTRXAM - sum(INV.CURTRXAM) OVER (PARTITION BY CR.CUSTNMBR ORDER BY INV.DOCDATE, INV.DOCNUMBR) < 0 THEN 0 ELSE CR.CURTRXAM - sum(INV.CURTRXAM) OVER (Partition by CR.CUSTNMBR order by INV.DOCDATE, INV.DOCNUMBR) end as AvailableBalance
    FROM RM20101 CR (nolock)
           JOIN RM20101 INV (nolock) ON CR.CUSTNMBR = INV.CUSTNMBR 
       INNER JOIN
    (
    SELECT CR1.CUSTNMBR, CR1.DOCNUMBR, MIN(DOCDATE) as MinPaymentDate
    FROM RM20101 CR1
    WHERE CR1.RMDTYPAL = 9
    AND CR1.CURTRXAM <> 0
    AND CR1.VOIDSTTS = 0
    GROUP BY CR1.CUSTNMBR, CR1.DOCNUMBR
    ) X ON X.CUSTNMBR = CR.CUSTNMBR AND X.MinPaymentDate = CR.DOCDATE AND X.DOCNUMBR = CR.DOCNUMBR

    WHERE  LEFT(INV.TRXSORCE,4) = 'SLST'
    AND INV.RMDTYPAL <> 8
           AND INV.CURTRXAM <> 0
       AND CR.RMDTYPAL = 9
       AND CR.CURTRXAM <> 0
    )
    SELECT
    CTE.Customer_Nbr, CTE.Apply_Date, CTE.Source_Document_Nbr, CTE.Check_Nbr--, CTE.Checkbook_Id, 
                  , CASE WHEN prev.AvailableBalance is null THEN CTE.Available_Apply_Amount else prev.AvailableBalance end as Available_Apply_Amount,
                  CTE.Apply_to_Document_Nbr, 
                  CTE.CURTRXAM AS [Invoice Balance], 
                  CTE.DOCDATE AS [Invoice Date],
    --CASE WHEN prev.AvailableBalance is null THEN 
    --CASE WHEN CTE.Available_Apply_Amount < CTE.CURTRXAM then CTE.Available_Apply_Amount ELSE CTE.CURTRXAM END 
    --ELSE prev.AvailableBalance end as Apply_Amount

    CASE WHEN prev.AvailableBalance is null AND CTE.Available_Apply_Amount < CTE.CURTRXAM THEN CTE.Available_Apply_Amount
    WHEN prev.AvailableBalance is null AND CTE.Available_Apply_Amount >= CTE.CURTRXAM THEN CTE.CURTRXAM
    WHEN prev.AvailableBalance <> 0 AND CTE.Available_Apply_Amount >= CTE.CURTRXAM THEN CTE.CURTRXAM
    WHEN prev.AvailableBalance <> 0 AND (CTE.Available_Apply_Amount - CTE.CURTRXAM) > 0 THEN  (CTE.Available_Apply_Amount - CTE.CURTRXAM)
    ELSE 0 END AS Apply_Amount

    FROM CTE
    LEFT JOIN CTE prev ON prev.rownum = CTE.rownum - 1 AND CTE.Customer_Nbr = prev.Customer_Nbr 

    Pivot - Table Output Help

    $
    0
    0

    Hi,

    I have the following code which outputs the standard table of 5 vertical columns

    select

    distinct(dbo.pk.job_number)as job_number,

    dbo.PK.Code,

    dbo.pk.name,

    FORMAT(DBO.DAD.INVOICE_DATE,'yyyy-MM')AS INVOICE_DATE,

    sum(dbo.DAD.draft_amount)as invoice

    from

    dbo.pk

    leftjoin dbo.dad

    on dbo.pk.job_number= dbo.dad.job

    groupby

    dbo.pk.name,

    dbo.PK.Code,

    dbo.pk.job_number,

    FORMAT(DBO.DAD.INVOICE_DATE,'yyyy-MM')

    How can I change the table output so that the Invoice_date variable essentially becomes a column so it's formatted something like this?

    Client_Codeclient_namejob_number2013-062013-092013-102013-112013-122014-012014-022014-03




    Failed to import csv data file

    $
    0
    0

    Hello SQL community,

    I cannot import my csv data file into the database. Does anyone know whats the issue?

    Thank You so much:)

    Regards,

    Tan




    VS 2015 shell - Oracle provider for Oledb not shown

    $
    0
    0

    Hi ,

    I am migrating to SSIS  2016 version. I am trying to use the Oracle provider for Oledb in connections.

    However, this option does not show. I have installed the Oracle client 12.2 and I am able to do UDL file testing, where in I can see the Oracle provider and able to test connection.

    But when I try in VS 2015, the option is not shown.

    The issue is described here  - https://jorgklein.com/2011/06/02/ssis-connect-to-oracle-on-a-64-bit-machine-updated-for-ssis-2008-r2/   and based on this I have installed the 64 bit client . But when trying to use the connection manager, the oracle provider is not shown.

    How to fix this?

    Performance upgrade op SQL VM

    $
    0
    0
    Hi,
    I did setup a new VM for SQL.  Software vendor installed SQL2017 on it and their application. Clients are complaining about performance and speed of the application.
    Is there a way i can approve the performance of the virtual machine or with other words the performance of the application.  by adding more VCPU ? more Memory ? other settings ??
    Any help would be welcome.

    This is the Host i use :
    HP DL380 G10 - 2 processors XeonSilver 4110 -  RAM 144Gb -  SAS disks 10K
    RAID5 -> Host
    RAID6 -> VM's

    These are the VM settings for the (VM) SQL-server
    1 Virtual CPU
    32Gb RAM (not dynamic)
    Disksize is 1Tb

    Regards,

    Jo

    Test Localdb

    $
    0
    0

    I know that udl can be used to test connection. But I always get errors when testing the connection to localdb.

    Can someone guide me how to test.

    Does SQL Server service account require database level permissions ?

    $
    0
    0

    Does the account under which the SQL Server service (i.e. Database Engine) runs require any SQL Server level privileges ?
    Or is it the case that it only requires Operating System level privileges ? 
    I understand that if one uses the 'NT SERVICE\MSSQLServer' (default) virtual account which is created by installation, 
    this account is automatically furnished with SQL Server System Administrator  role.
    What happens if I want to use a random domain account to run the SQL Server service under ?
    Does this need any SQL Server level permissions ?
    I have found documentation for SQL Server Agent service which states that it requires SA role on DB level.
    However I have not managed to find any for the SQL Server service (i.e. Database Engine).

    Thanks.

    Query to get column from multiple tables but don't join?

    $
    0
    0

    Hi guys, I am trying to run a query from PowerShell to get the contents of a column from multiple tables. The columns will not have the same amount of data within it so I don't want to join them. I'm wanting to get it all in one result so that i can dot source the output in PowerShell

    SELECT [ImpactDefinition].[NAME] AS Impact, [RequestTypeDefinition].NAME AS RequestType, [UrgencyDefinition].NAME AS Urgency, [CategoryDefinition].CATEGORYNAME AS Category
    FROM [ImpactDefinition], [RequestTypeDefinition], [UrgencyDefinition], [CategoryDefinition]

    This give me the info that I want, but it gives me duplicates for each possible combination.

    I tried to google around to see how to join with out matching but i guess i don't know the terminology used in SQL.

    Viewing all 8979 articles
    Browse latest View live


    <script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>