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

Job failing due to resource being used.

$
0
0

Hi,

I have a backup job failing due to the backup being used by something else.

The backup job deletes the old backup before a new backup is taken and this is where the job is failing.

My question is, is there a query that will show what is using the old backup so I can run the job without it failing again?

Thanks in advance.


Cannot install ODBC Driver 11 for SQL server anymore

$
0
0

Since a few days (??) I cannot install the 32 or 64 bit ODBC drivers v11 for SQL anymore on any system. I have installed them earlier in de the last months without problems.

Even when I uninstall them en reinstall (using the same downloaded file that I installed them with earlier) I can't install.

Error is: operating system not supported.

Problem on different 32/64 bit Win7 and Win8 systems.

 

How to add SSMS to git source control?

$
0
0

Hi Everybody,

I want SSMS (SQL Server Management Studio) to be under source control Git. I have googled it and it was said that a source control plug-in needed to do that. But can't find any information or download link for the source control plug-in. Can't proceed.

Please help.

Thanks and Regards,

Anujit Karmakar


Anujit Karmakar Sr. Software Engineer

ODBC Connection Issue. to Connect to SQL 2008 R2 using SQL Server Driver 6.01.7601.17514

$
0
0

I am trying to create a System DSN using the SQL Server Driver Version 6.01.7601.17514 to a SQL Server 2008 DB.

I am able to create a successfull connection using hte SQL Native Client 11. But when i try to connect to the same DB using the SQL Server Driver, I am getting the below error. Any inputs on why this works with one and not with the other. Also, whats the difference between the two drivers.

SQL State 01000

Server Server Error : 14

[Microsoft][ODBC SQL Server][DBNetLIB]COnnection Open [InvalidInstance()]

Connection Failed:

 SQL State 08001

Server Server Error : 14

[Microsoft][ODBC SQL Server][DBNetLIB]Invalid Connection


- Maruthi Shangar

connecting tables

$
0
0

guys,

 i am trying to learn SQL. I purchased the mta book and some other ones. I do like those book but i encountered some problems.

One of them is that i dont know how to connect different tables with PK?FK.

Lets say i got three tables, one is called food, the other one drinks and the third one snacks. How can i connect these through the sql code?

thanks in advance.

Data in columns instead of rows

$
0
0

I'm writing a view that has 2 tables: One table has customer information, the other has sales data (detail). I'm trying to return data in columns that sums all sales data by customer for the past 5 fiscal years. I'm easily able to accomplish this in a row format, but each customer has 5 rows...one row for each fiscal year.

My ideal would be to create the following format:  Customer name, 2015 sales, 2014 sales, 2013 sales, etc.  All in one record. 

Can anyone point me in a direction on how to do this vs. return each year in individual rows (using group by)?

Thanks,

Troy

insert date values in a table created on sql server management studio

$
0
0
I have created a table using the below query
CREATE TABLE job_history (
  EMPLOYEE_ID decimal(6,0) NOT NULL,
  START_DATE date NOT NULL,
  END_DATE date  NOT NULL,
  JOB_ID varchar(10) NOT NULL,
  DEPARTMENT_ID decimal(4,0) DEFAULT NULL,
  PRIMARY KEY (EMPLOYEE_ID,START_DATE)
  )
And when I try to update values in the created table using the below query

INSERT INTO job_history VALUES
(102, '1993-01-13', '1998-07-24', 'IT_PROG', 60),
(101, '1989-09-21', '1993-10-27', 'AC_ACCOUNT', 111),
(103, '1993-10-28', '1997-03-15', 'AC_MGR', 110),
(201, '1996-02-17', '1999-12-19', 'MK_REP', 20),
(114, '1998-03-24', '1999-12-31', 'ST_CLERK', 51),
(122, '1999-01-01', '1999-12-31', 'ST_CLERK', 50),
(200, '1987-09-17', '1993-06-17', 'AD_ASST', 90),
(176, '1998-03-24', '1998-12-31', 'SA_REP', 80),
(175, '1999-01-01', '1999-12-31', 'SA_MAN', 81),
(201, '1994-07-01', '1998-12-31', 'AC_ACCOUNT', 91),
(0, '0000-00-00', '0000-00-00', '', 0)
I get an error saying "The conversion of a varchar data type to a datetime data type resulted in an out-of-range value."  how to resolve this? I tried it for .

Change Host Name after Default SQL Server 2008R2 is installed?

$
0
0

Hi All,

Client has a requirement and wants to change host Name after we have installed default SQL Server 2008R2. Is it possible to achieve this.

Please suggest.

Regards,

Kalyan


Grateful to your time and support. Regards, Shiva


Why is my transaction file growing when db is in simple mode and there are no waiting transactions

$
0
0

I noticed that my database log file has reached 160GBs. My database is in simple recovery mode and I used the following query to see if there are any waiting transactions.

SELECT d.name,d.log_reuse_wait,d.log_reuse_wait_desc
FROM sys.databases d

It returned log_reuse_wait 0 and description 'NOTHING'. Why is my transaction log growing then? Please advice.



mayooran99

Export view to cell in excel template

$
0
0

Hi everyone,

I accidentally posted this on the wrong forum section. Guessing this is the proper place for it:

Just wondering - is it possible to take an existing excel template and insert the results of a query into a specific cell on that template? When I run my query using the "from sql server" option that excel has the results overwrite the template. I had trouble finding any threads on this.

Thank you

How can I replace the cursor in the below query?

$
0
0

I have this below query which calls a stored procedure that takes only 1 item's attributes at a time. But because of performance problems we are required to remove the cursor. How can I replace the below cursor logic with set operations or CTE? Please advice.

DECLARE db_cursor_ava CURSOR
    FOR
        SELECT t.[agent-id],
               t.[start-date],
               t.[end-date],
               t.[monitor-days],
               t.[monitor-start],
               t.[monitor-end],
               t.[timezone-offset]
        FROM   @tmpAgentPeriodTimeRange t

    OPEN db_cursor_ava
    FETCH NEXT FROM db_cursor_ava INTO @agentID_ava,
    @stDateTime_ava,
    @endDateTime_ava,
    @monDays_ava,
    @monSt_ava,
    @monEnd_ava,
    @offset_ava

    WHILE @@FETCH_STATUS = 0
    BEGIN
        DELETE
        FROM   @tmpMonitorPeriod

        DELETE
        FROM   @tmpFinalResult

        SET @runID = 1

        IF(@endDateTime_ava>DATEADD(MI,@offset_ava, GETUTCDATE()))
        BEGIN
            SET @endDateTime_ava=DATEADD(MI,@offset_ava, GETUTCDATE())
        END


        INSERT INTO @tmpMonitorPeriod
        EXEC core.usp_GetMonitoringPeriod
             @startDate = @stDateTime_ava,
             @endDate = @endDateTime_ava,
             @monitoringDays = @monDays_ava,
             @monitoringStart = @monSt_ava,
             @monitoringEnd = @monEnd_ava

        SELECT @maxID = MAX(tm.id)
        FROM   @tmpMonitorPeriod tm



        FETCH NEXT FROM db_cursor_ava INTO @agentID_ava,
        @stDateTime_ava,
        @endDateTime_ava,
        @monDays_ava,
        @monSt_ava,
        @monEnd_ava,
        @offset_ava
    END

    CLOSE db_cursor_ava
    DEALLOCATE db_cursor_ava


mayooran99

List of tables count and Views count in schema wise

$
0
0

Hi All,

I want to get all tables count and views count in Schema wise, What is the query for that?

Thanks in Advance.

SQL Server 2008 R2 Standard - Compatibility issues with Windows Server 2012 R2

$
0
0

Hello,

We used as a test a box on which we installed Windows Server 2012 R2 and SQL Server 2008 R2 Standard Edition. No Service pack was installed. It worked perfect.

Now we try to do it on another box and all of the sudden there is compatibility issue when we try to instal SQL Server. We can still install SQL Server by clicking "Continue without getting help".

Where can this come from? If it is hardware related what are the thing I should look at?

Thanks all


TempDB mdf error

$
0
0

Hi Experts,

We are receiving this error to TEMPDB MDF :

SQL Server detected a logical consistency-based I/O error: incorrect checksum (expected: 0xcdda157a; actual: 0x7fec48fa). It occurred during a read of page (1:32448) in database ID 2 at offset 0x0000000fd80000 in file 'E:\Program Files\Microsoft SQL Server\MSSQL10_50.abcSSQL01\MSSQL\DATA\tempdb.mdf'.  Additional messages in the SQL Server error log or system event log may provide more detail. This is a severe error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.

SQL Errorlog says:

DBCC CHECKDB (tempdb) executed by abc-usa\sqldba1 found 0 errors and repaired 0 errors. Elapsed time: 0 hours 0 minutes 0 seconds and errors related to any drives in event log.

When we got his error few days back we RESTARTED SQL but again today it is appearing.

I googled for this, we get many solutions for all other databases except tempDB mdf file issue, can someone help me how to fix this issue as RESTARTING did not fix thought tempDB gets created every restart.

Thanks in advance.

How to validate the dates ie., compare the date values with one another

$
0
0

table structure

ID Col A   Col B

1  empno   [20141127-20151128]1234

1  empno   [20151201-99991231]232544

1  salutation  [20141127-99991231]Mrs

1  salutation  [20151127-99991231]Mr

2  empno   [20141127-20151128]1234

2  empno   [20151201-99991231]232544

2  salutation  [20141127-99991231]Mrs

2  salutation  [20151127-99991231]Mr

Issue Details:

so my requirement is to find the list of overlapping records based on the dates

user details may be varying from time to time in our system new data would be pushed. We have a tool in which we would push these data where we have applied a filter to accept on those users who are not having overlapping issues with the dates.

Overlapping Issue Example:

The users employee id for two years it is 1234 and later he moved to another department and his employee id got changed and it became 2345 remaining all details are same. So the main employee systems send the data for this user as empno - [20141127-20151128]1234 and empno - [20151201-99991231]232544

it means from 20141127 to 20151128 his employee no is 1234 and from 20151201 to 99991231 his employee would be 2345.

This is a correct case and the tool would accept this data.

the below cases are invald

Case 1: 1 salutation [20141127-99991231]Mrs

             1 salutation [20151127-99991231]Mr

Case 2: 2 salutation [20141127-99991231]Mrs

            2 salutation [20141127-99991231]Mr

So we wanted to find these overlapping records from tables.

Query:

I am able to successfully write query for the case 2 type but unable to write for case

 

select id,colA

count(left(ColB,CHARINDEX(']',ColB))) as 'Count'

from tblA with (nolock)

where id in (Select distinct id from tblb with (nolock))

group by id, cola,left(ColB,CHARINDEX(']',ColB))

having count(left(ColB,CHARINDEX(']',ColB)))>1


Why are transactions long running?

$
0
0
My stored procedure has a transaction blog. I pick up a record from a database and process it in that transaction block. I noticed that my transaction log has grown in gigabytes. But my transaction block would execute for the 2nd time only when it has finished processing the 1st time right? Because as I mentioned my transaction block executes each time for a record in a table. So 2nd record won't be picked until 1st record is finished processing. So how come my transaction log has grown into GBs? Like until the 1st time transaction block finishes executing, other records won't be processed, meaning the same transaction block in the same SP wont be visited. So why is my log growing? It is showing active transaction when i execute the dbcc opentran command. Please advice

mayooran99

error al conectarme a bd de sql-server lenguaje c.

$
0
0

Ayuda por favor 

necesito conectarme a la base de datos en sql-server

a travez de lenguaje c

pero me manda el error: Undefined referenceto 'SQLDriverconnect@32'

#include <stdio.h>
#include <windows.h>
#include <winnt.h>
#include <sql.h>
#include <sqlext.h>

main() {
SQLRETURN ret;
SQLHDBC dbc; /* assume already allocated */
ret = SQLDriverConnect(dbc, NULL, "DSN=Lacandon;", SQL_NTS,
                       NULL, 0, NULL, SQL_DRIVER_COMPLETE);
}


sssssss

Granting permissions.

$
0
0

Hi Experts,

I am need to grant view definition permission to view all the stored procedures of around 50 database to a user, for which I have used 

EXEC master.dbo.sp_MsForEachDB 'USE [?]; GRANT VIEW Definition TO [abc\user];', the command completes successfully, but when I verified manually randomly for Stored procedure permission, nothing seems to be there at permissions level of the stored procedure.

Note: the user is mapped to all the databases.

Please help me where I am going wrong.

And  I have got one more option to do this, below is the code:

Thanks in advance.


Automate backup and restore

$
0
0

Hi All,

I want to automate backup and restore operation in T-sql script I need to give resource server,database and backup file location as input and then I need to restore that backup in differenet server so I want to give destination server as input too.

Could somebody help me on it.

Thanks

PROBLEM CONNECTING TO SQL 2008 EXPRESS WITH CLASSIC ASP ON SMALL PRIVATE NETWORK

$
0
0

I created a private wireless network (no internet connection) of four workstations, each running an installation of SQL 2008 Express.  All four laptops are running Windows 7 Professional.  I created a HomeGroup for this private network.  While I don't care about file sharing between the four workstations, I do need three of them to be able to connect to the SQL 2008 Express database on the fourth laptop via connection strings in classic ASP programs.  Each of the four laptops can see the others in the network.  I can ping the ip addresses from each to the other with no problems.  When I try running the ASP program on the three laptops that attempt to connect to the SQL database on the fourth, I get the Server does not exist or access denied error '80004005'.  The same program can also run on the fourth laptop and connects to the SQL database with no problems.  I've tried using SQLOLEDB and SQLNCLI10 as the provider in the connection string on the other three.  That fails.  I've tried adding the IP Address of the laptop where the SQL Database resides as the Data Source in the connection string on the other three and that still fails.  TCP/IP and Named Pipes are enabled.  Each laptop can connect to the instance of SQLEXPRESS running on each, but I need the three to be able to connect to the instance of SQL Express running on the fourth.  Any ideas what I may be doing wrong?  This connection string works fine in the ASP program to connect to the local database on each laptop:   

Connection.Open "PROVIDER=SQLOLEDB;Server=ComputerName\Sqlexpress;UID=MyUser;PWD=MyUserPassword;DATABASE=MyDatabase"

Nothing seems to work for the Connection String that the other three laptops need to use to connect to this database on the fourth laptop.

Viewing all 6989 articles
Browse latest View live


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