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

SQL 2008 Trigger to handle multi rows scenario

$
0
0

I have created below trigger to start logging the company changes from the table1 into another audit table. It works fine with single row but crashing with identical change with multiple rows. Can you please help me to update the trigger to handle multi-row scenario. Thanks.

GO

IFNOTEXISTS(SELECT *FROMsys.objectsWHEREobject_id=OBJECT_ID(N'[dbo].[Company_AuditPeriod]')ANDtype in(N'U'))

CREATETABLE [dbo].[Company_AuditPeriod](

      [Client] [varchar](25)NOTNULL,

      [Period] [varchar](25),

      [Table_Name] [varchar](25),

      [Field_Name] [varchar](25),

      [Old_Value] [varchar](25),

      [New_Value] [varchar](25),

      [User_ID] [varchar](25),

      [Last_Update] [datetime],

        [agrtid] [bigint]IDENTITY(1,1)NOTNULL,

)ON [PRIMARY]

GO

--create trigger

SETQUOTED_IDENTIFIERON

GO

CREATETRIGGER [dbo].[Table1_Update]

ON [dbo].[Table1]

FORUPDATE

NOTFORREPLICATION

AS

BEGIN

     DECLARE

      @status          varchar(3),

      @user_id   varchar(25),

      @period          varchar(25),

      @client          varchar(25),

      @last_updatedatetime

     

     DECLARE

      @Old_status      varchar(3),

      @Old_user_id     varchar(25),

      @Old_period      varchar(25),

      @Old_client      varchar(25)

     SELECT

      @status    =status,

      @user_id   =user_id,

      @period          = period,

      @client          = client,

      @last_update= last_update

     FROM Inserted

     SELECT

      @Old_status=status,

      @Old_user_id     =user_id,

      @Old_period      = period,

      @Old_client      = client

     FROM Deleted

     If @Old_status <> @status

           INSERTINTO Company_AuditPeriod

           VALUES ( @client, @period,'Table1', 'period',@old_status, @status, @user_id, @last_update)

END

GO



How do i get the approximate size of back up file required to save on disk using sql query because i want to show the required sapce for backup on my application

$
0
0
hi i am face with problem that is i want to show the how much approximate space required for backup or .bak file to get backup using sql query because i want to show the required memory for backup file on my java application  

What is cross version instances ?

$
0
0

Greetings,

      I am in the process of preparing a document for upgrading our SQL Server 2000 servers to SQL Server 2008, I read the details in the technet SQL Server 2008 online books, but I didn't understand the below line, can anyone explain this in simple words to understand ?

  • Cross-version instances of SQL Server 2008 are not supported. Version numbers of the Database Engine, Analysis Services, and Reporting Services components must be the same in an instance of SQL Server 2008.

Is that possible to have different version number of database engine during upgrade ?

With regards,

Gopinath.


With regards, Gopinath.

Unable to call sql scalar-valued function within Server

$
0
0

I have created a scalar-valued function within my server: dbo.BikeMaintIncident_Count

This is the function: ------------------------------
USE [Maint]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
FUNCTION [dbo].[BikeMaintIncident_Count]
(
    @BikeID int,
    @BikeTaskID int
)
RETURNS INT
AS
BEGIN
    RETURN(SELECT COUNT(Bike_Task_ID) as Count
            FROM Maint_Incident
            WHERE Bike_id = @BikeID
            AND Bike_Task_id = @BikeTaskID
            Group by Bike_Task_id)
END
------------------------------

I can "see" it in the SSSI browser and from the sqlserver object browser in VB.Net but when I try to execute a sql query to display the return variable the sql query doesn't display the function to choose it, and when I attempt to call it from VB.NET (ExecuteScalar()) I get an exception message that the function can't be found.  I'm guessing I haven't, somehow, "recorded" it properly within the server.  Any help would be greatly appreciated.

Thanks, Minuend

 photo Scalar_Function.png" /> photo Scalar_Function.png" />

Connect Team Project with Sql Server Database

$
0
0

Hi,

Am supposed to be doing a database team project. I have a local instance of sql server but I should also make this database available on the team project. How do i go about this? For now, most information just lies on the codes which is clear but when dealing with databases there's very scanty information

SQL Server 2012

$
0
0

Hello everyone,

I hope that this mail finds you in good health, where can i get a copy of SQL SERVER 2012 DEVELOPER edition?

Thanks and Kind Regards,

Siyanda Khumalo

SQL SERVER RPC Configuration issue 2014

$
0
0

Hi Every one,

I am getting below error message when i run remote store proc

Error number: 7411

Error message : Server 'XYZ' is not configured for RPC.

I did set RPC and RPC out to true in my linked server properties

I am running from  sql2014  and store proc located in  sql 2008r2

I check config manger for tcp/ip all enabled in network configuration.. 

Am i missing any thing?

Any help much appreciated

Thanks

Pull Data form DB while C1+C2-C3 < 0

$
0
0

Hi Everyone, 

I would like to pull out from SQL server only records that satisfy the following conditions   C2+C3 -C4 < 0

thanks


regarding sqlserver

$
0
0

Hi,

i have one  emp table

empid    name  deptid   sal

1    kot    4    2000
2    viss    2    1000
3    pra    1    1000
4    ram    3    1000
5    fff    1    20000
6    fty    3    20000
7    hyyy    4    20000
10    kotiii    2    20000

in this i want to retrieve whose salary is greater than avg salary of each their departments

connection error

$
0
0

Team,

Please can you some one shed some lights on the below error

sql server version : Microsoft SQL Server 2012 (SP1)

log error show below :

" Service was unable to open new database connection when requested.
Exception Connection Timeout Expired.  The timeout period elapsed during the post-login phase.  The connection could have timed out while waiting for server to complete the login process and respond; Or it could have timed out while attempting to create multiple active connections.  The duration spent while attempting to connect to this server was - [Pre-Login] initialization=270; handshake=9567; [Login] initialization=0; authentication=0; [Post-Login] complete=10642; Connection string - Data Source=*********;Initial Catalog=solarwinds;User ID=orion;Password=*******;Connect Timeout=20;Load Balance Timeout=120;

BR

PGR

Service Broker needs to access the master key in the database 'mydatabase'. Error code:26. The master key has to exist and the service master key encryption is required.

$
0
0

Hi all,

One of mydatabase using  "Service Broker ",I'm getting below error in Error log but I can seeService Broker is enable in the server.

Service Broker needs to access the master key in the database 'mydatabase'. Error code:26. The master key has to exist and the service master key encryption is required.

Please some body let me know what is issue ? and how resolve this issue.

I appreciate your help, Thanks in advance.

Regards

regarding sqlserver

$
0
0

Hi,

i have one table

empid     name  managerid

1              a        null

2               b        null

3               c         2

4               d         2

my output should be

empid      name    managerid

1              a        null

2               b        null

3               c         b

4               d         b

please help me

Server in unavalable

$
0
0

I see in my SQL server 2008, I see server is unavailable. How to make it available?

Failed to initialize sqlcmd library with error number -2147467259

$
0
0

I'm trying to get SQL Server to send an email.  The test email works fine; basically DBMail works properly.  The thing is, if a human runs it, everything is fine.  If I schedule it using Sql Server Agent Job, nothing works.  I think this has something to do with a proxy, or some such thing. Any thoughts on what could be wrong?

As I know, the security features are much different than those from earlier versions.

I'm using SQL Server Developer Edition 2014.


Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

How do I launch SQL Server Data Engine in windows 8.1 64 bit.

$
0
0
I've installed SQL Server 2014 in my computer running Windows 8.1 Enterprise Edition 64 bit. I cannot figure out how to find SQL Server Management Studio. I've tried searching forsqlservr.exe, but that only opens a command line interface that gives random error messages and promptly closes.

the build number of the sql server 2008 not changed after completion of the SP1 ?

$
0
0

Hi All,

I faced different issue while installing the SP1 on sql 2k8 RTM, after successfully completion of the SP1 installation, I found the build number shows the old number only.

could you please guide me how to work further on this issue and let me know reasons ?

Thanks,

Full Text Index with docx and xlsx is not working

$
0
0

Hi,

I am Having a sql server 2012.In My DB, I have one table. In this table, having one colum Document and its datatype is

Image data type. I have created a fulltextindex on this table.If i searching a word in .doc, it will give a result.But if i search a word in .docx,It wont give any result.Why it is not working?Please give me a good installation.

Regards,

Dileep

SQL server password policy

$
0
0

In SQL server 2005 and 2008, is there a TSQL query to show for all sql authentication accounts, whether they are subject to password complexity and/or password expirty policies?

Is the password complexity policy a feature with MSSQL itself, or is it linking to the password policy on the operating system?

guest account

$
0
0
Is there anyway to query via TSQL, to list all databases in a SQL instance (2000, 2005 and 2008) to list if the guest account has access to the database?

SELECT top two longest running steps from a log file

$
0
0

Simplified example.

Our jobs write records to our own internal log file. I want to write a query that will pull log records for a specific job, between specific dates. This will help determine if the job is running slower than usual and to find the steps within the job that are the longest running.

Jobs are identified by the Type field. Type=1 is a specific job name.

Each job writes a DESC=START record to the log at the beginning of the job. the Desc=START record will be updated at the end of the job with the ENDDT.

I want to pull the top two longest running steps (ENDDT-BEGINDT) for each job (Type) where the step startdr and enddt falls between the START startDT and end dt.

I also want to always pull key step names, like DESC=START and DESC=xya for each job.

LOG RECORDS

DESC,TYPE,BEGINDT,ENDDT
START,1,2014-10-22 07:56:56.000,2014-10-22 09:56:56.000
aaa,1,2014-10-22 07:57:56.000,2014-10-22 08:57:56.000
bbb,1,2014-10-22 08:57:56.000,2014-10-22 09:01:56.000
ccc,1,2014-10-22 09:01:56.000,2014-10-22 09:56:56.000
xya,1,2014-10-22 09:55:56.000,2014-10-22 09:56:56.000
START,1,2014-10-21 11:56:56.000,2014-10-22 02:56:56.000
aaa,1,2014-10-21 11:57:56.000,2014-10-22 01:57:56.000
bbb,1,2014-10-22 01:57:56.000,2014-10-22 02:56:56.000
ccc,1,2014-10-22 02:56:56.000,2014-10-22 02:56:56.000
xya,1,2014-10-22 09:55:56.000,2014-10-22 09:56:56.000


Desired result set.

If pulling job type 1 records for last 2 days, would end up with this result set. START and xya are always pulled and then the top 2 longest running steps for each of the START records.

DESC,TYPE,BEGINDT,ENDDT,Duration
START,1,2014-10-22 07:56:56.000,2014-10-22 09:56:56.000
aaa,1,2014-10-22 07:57:56.000,2014-10-22 08:57:56.000
ccc,1,2014-10-22 09:01:56.000,2014-10-22 09:56:56.000
xya,1,2014-10-22 09:01:56.000,2014-10-22 09:56:56.000
START,1,2014-10-21 11:56:56.000,2014-10-22 02:56:56.000
aaa,1,2014-10-21 11:57:56.000,2014-10-22 01:57:56.000
bbb,1,2014-10-22 01:57:56.000,2014-10-22 02:56:56.000
xya,1,2014-10-22 09:55:56.000,2014-10-22 09:56:56.000

I am asking for help in how to create this query. Thanks

Viewing all 8979 articles
Browse latest View live


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