Thursday, June 20, 2013

[SQL Server] IN and EXISTS

[SQL Server] IN and EXISTS


IN and EXISTS

Posted: 20 Jun 2013 09:06 AM PDT

I'm trying to really [b]understand[/b] the difference between IN and EXISTS. Would the following be fair statements?IN• first evaluates: inner query• evaluates outer query until: every row in outer query's table examined• accepts as argument: a list of literal values or a condition (most often used when argument is a list of literal values)• is faster when inner query's table contains: few records / values• is usually: slowerEXISTS• first evaluates: outer query• evaluates outer query until: inner query finds a record that satifies condition (if inner query doesn't find any records that satify condition: until every row in outer query's table examined)• accepts as argument: a condition• is faster when inner query's table contains: many records• is usually: faster

Select only rows with Max Value on a column with multiple tables

Posted: 20 Jun 2013 08:04 AM PDT

The query returns all the rows needed but you can see the bottom 4 rows are duplicates of each other except for the limit_ver_num field. We want to return the first 8 rows and the two rows where limit_ver_num = 2. We want to return the row with the largest limit_ver_num if there is a duplicate record.So the correct results would include rows 1-9 and row 11 Rows 10 and 12 should not be included in the resultsMy current example is in SQL 2008 but will eventually be used in Oracle if that matters[code="sql"]SELECT sam_typ_tst_typ.SAMPLE_TYPE_NUM, sample_type_name, method_name, method_descr_text, test_type_name, limit_ver_numFROM sam_typ_tst_typ, SAMPLE_TYPE, method, limits, test_type, areawhere sam_typ_tst_typ.sample_type_num = sample_type.sample_type_num andsam_typ_tst_typ.TEST_TYPE_NUM = test_type.test_type_num andsam_typ_tst_typ.METHOD_NUM = METHOD.METHOD_NUM andsam_typ_tst_typ.SAMPLE_TYPE_NUM = LIMITS.sample_type_num ANDsam_typ_tst_typ.TEST_TYPE_NUM = LIMITS.TEST_TYPE_NUM ANDSAMPLE_TYPE.AREA_NUM = AREA.area_num andsam_typ_tst_typ.SAMPLE_TYPE_NUM in (select SAMPLE_TYPE_num from SAMPLE_TYPEWHERE SAMPLE_TYPE_NAME = 'MEHCN_INPROCESS');[/code]The row column here is strictly to help count the rows, it is not an ID columnOUTPUT:[code="sql"][b] STN method_descr_text test_type_name limit_ver_num[/b]1 1967 % WATER IN HCN PRODUCT Water % 12 1967 SULFUR DIOXIDE Sulfur Dioxide 13 1967 PROPIONITIRLE Propionitrile ppm 14 1967 ACRYONITRILE Acrylonitrile ppm 15 1967 ACETONITRILE Acetonitrile ppm 16 1967 % Acidity in HCN HCN PR Acidity 17 1967 NH3 IN EP78 - HC Ammonia ppm 18 1967 % ACIDITY IN HC ST BTM Acidity 19 1967 PACKED COOLER PH pH 210 1967 PACKED COOLER PH pH 111 1967 %ACIDITY IN PACKED PK CLR Acidity 212 1967 %ACIDITY IN PACKED PK CLR Acidity 1[/code]I've tried to get this using:SELECT sam_typ_tst_typ.SAMPLE_TYPE_NUM, sample_type_name, method_name, method_descr_text, test_type_name, MAX(limit_ver_num)FROM sam_typ_tst_typ, SAMPLE_TYPE, method, limits, test_type, areawhere sam_typ_tst_typ.sample_type_num = sample_type.sample_type_num andsam_typ_tst_typ.TEST_TYPE_NUM = test_type.test_type_num andsam_typ_tst_typ.METHOD_NUM = METHOD.METHOD_NUM andsam_typ_tst_typ.SAMPLE_TYPE_NUM = LIMITS.sample_type_num ANDsam_typ_tst_typ.TEST_TYPE_NUM = LIMITS.TEST_TYPE_NUM ANDSAMPLE_TYPE.AREA_NUM = AREA.area_num andsam_typ_tst_typ.SAMPLE_TYPE_NUM in (select SAMPLE_TYPE_num from SAMPLE_TYPEWHERE SAMPLE_TYPE_NAME = 'MEHCN_INPROCESS')GROUP BY sam_typ_tst_typ.SAMPLE_TYPE_NUM, sample_type_name, method_name, method_descr_textWhen I use this query I get this message:Msg 8120, Level 16, State 1, Line 1Column 'test_type.test_type_name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.Help please, I do some sql work but this is outside anything I've tried to find before. The above may end up working but I don't understand the GROUP BY function well enough to modify it correctly with so many tables involved.

Convert VBA Function to T-SQL or some other object - what would be best?

Posted: 20 Jun 2013 08:34 AM PDT

An Access Programmer - with Linked SQL Tables - Any ideas on the best way to approach this design would be welcome?Here is a simple function that returns a True/False written in MS Access.It is part (1 of 180) of a Rules Engine. In a MS Access Query for example, the query can call Column1 [ID_Building] Comun2 StakingStatus: Building_Status_Staking_Does_Building_FieldWorkDate_Land([ID_Building]) The output would be something like 343434 TrueFor small pulls of a dozen records, it cost a few mili-seconds. The SQL Server Native Client actually does convert it to some sloppy T-SQL.The problem is - I will soon have about 120 columns with more complex rules. Times around 100 to 500 concurrent users.Should I use a Stored Procedure, a TSQL pass-through query, or other method?This is a Rules Engine under development. The rules are run when one of many key fields across many forms are changed.Each user passes in a single [ID_Building] for a session that has around 30 forms (not all open of course) If they change one value, the rules engine evaluates all of the rules and updates a dashboard that needs to give the appearance of "real-time". (e.g. within 1 to 10 seconds).Think about a tax form: change a dependent from 1 to 2, you are a homeowner, 2 incomes, with rental income, .... - the change from 1 to 2 activates a Dashboard that "recommends you file separately" [code="vb"]Public Function Building_Status_Staking_Does_Building_FieldWorkDate_Land(ID_Building) As Boolean ' Rule Building Status - Staking Staking Status Can NOT have an a Field Work Date of type LAND Dim rstMisc As DAO.Recordset Dim SQLMisc As String ' NOTE Added IP Date afterwards10 Building_Status_Staking_Does_Building_FieldWorkDate_Land = False ' set function to false until proven true SQLMisc = "SELECT APD_FieldWorkDate_2.ID_Buildings, APD_FieldWorkDate_2.ID_Bio_Svy_Type FROM APD_FieldWorkDate_2 " & _ "WHERE (((APD_FieldWorkDate_2.ID_Buildings)=" & ID_Building & ") AND ((APD_FieldWorkDate_2.ID_Bio_Svy_Type) In (15,18)));"30 Set rstMisc = CurrentDb.OpenRecordset(SQLMisc, dbOpenDynaset, dbSeeChanges)40 On Error Resume Next50 rstMisc.MoveLast 60 If rstMisc.RecordCount > 0 Then70 Building_Status_Staking_Does_Building_FieldWorkDate_Land = True80 Else90 Building_Status_Staking_Does_Building_FieldWorkDate_Land = False100 End If110 If Err.Number <> 0 Then120 Err.Clear130 Exit Function140 End If ' A Case statement would be OK too.End Function[/code]

Very specific query

Posted: 20 Jun 2013 03:07 AM PDT

Hello All,I have no idea at all how to do next:Table:[u]ID_____Type_____ Term[/u]1_____Subject_____ sky2 _____Next _____ earth 2 _____Subject_____video 3_____Test _______black 4_____Subject _____white4_____ Subject _____paper4 _____Forms _____ red4_____Subject _____stone5_____Test ________head6 ____Subject _____ leg6 ____Subject _____ waterQuery should check Subject in Type field and in a case of COUNT(ID) = 1 (and Type = Subject), field Result will be Term.In a case of COUNT(ID) > 1 (and Type = Subject), field Result will be Term + ',' + Term + ',' ... ',' + TermFrom table above:[u]ID_____[/u][u]Result[/u]1_____ Sky2_____ video4_____ white, paper, stone6_____ leg, waterAny idea?Thanks,Brano

splitting up a start time and end time into different dates

Posted: 20 Jun 2013 12:22 AM PDT

what i need to do is find the hours both in the AM and PM for each day. so lets say i have the start date 6/20/2013 8:00:00 end date 6/22/2013 17:00:00 i need the out put for each day in AM and PM hours. so the out put would look like:Date-AM-PM6/20/13 - 4 - 56/21/13 - 4 - 56/22/13 - 4 - 5the problem i'm having is that each date that's read in will not always be the same. some times it will only be one day between, others times it will be three days each with different starting time. currently if it one day i have been using: DateDiff(hh,cast(Convert(varchar(2),start,108)as int),cast(Convert(varchar(2),12,108)as int)) to find the AM hours. Any suggestions would be helpful, thank you

questions about CREATE LOGIN

Posted: 20 Jun 2013 02:49 AM PDT

I know I can create a login as follows:CREATE LOGIN test_loginWITH PASSWORD = 'some_password', DEFAULT_DATABASE = AdventureWorksDW, -- or whatever databaseDEFAULT_LANGUAGE = us_english, CHECK_POLICY = OFF;I also know that, if I'm in SQL Server Management Studio and I enable Query | SQLCMD Mode, instead of CREATE LOGIN test_loginI can use:setvar LoginName "test_login"CREATE LOGIN $(LoginName)in the above SQL code.• What is the advantage of using the latter method?• Is there a way I can use the latter method from outside of SQL Server Management Studio (like when I'm using SQL commands in some app)?• In SQL Server Management Studio, I don't see any indication when SQLCMD Mode is enabled or it's not, so if I forget whether I've enabled it, I just have to play with it to find out for myself. Am I missing something? How can I tell?• I know that in the above example, AdventureWorksDW can be enclosed in square brackets as follows:DEFAULT_DATABASE = [AdventureWorksDW],and the command will still work. But what effect, if any, does this have on the CREATE LOGIN command?

Need some help with retrieving correct Device IP Address

Posted: 19 Jun 2013 11:43 PM PDT

All, we got Inventory system that runs in our environment collecting hardware/software information. I like to setup system, that checks the workstation IP Address/IP Subnet and matches that against our Location table and retrieve the location based on IP Information. With people working from home; Virtual Machines, etc.. it's not that straight forward, as devices now have multiple IP Addresses assigned.Find below DDL, and some scenario's that I need help withDECLARE @IPInfo TABLE( MachineId int NOT NULL, IPAddress varchar ( 255 ) NOT NULL);-- Add some sample dataINSERT INTO @IPInfo( MachineId, IPAddress)VALUES( 1, '143.1.96.29' ),( 1, '192.168.0.12' ),( 2, '143.34.96.0' ),( 2, '172.20.10.0' ),( 3, '155.119.212.212' ),( 4, '192.168.1.55' ),( 5, '172.20.25.55' ),( 6, '10.1.55.212' ),( 6, '155.119.232.22'),( 7, '192.168.2.55'),( 7, '192.44.55.212')select * from @IPInfoMachineId IPAddress1 143.1.96.291 192.168.0.122 143.34.96.02 172.20.10.03 155.119.212.2124 192.168.1.555 172.20.25.556 10.1.55.2126 155.119.232.227 192.168.2.557 192.44.55.212I've tried this using GROUP BY with MIN(IPAddress) Option.this works to some extend, but not in all scenario's.I try to filter out what is known as RFC1918 addresses but only if workstation has multiple IP Addresses, we do have in our environment Desktops and they in most cases only have 1 IP Address.The RFC1918 range is 10.0.0.0/8 172.16.0.0/12 192.168.0.0/24What I try to do is followingWHen Machine has multiple IPAddresses, and need to filter out the RFC1918 addresses somehow, the option with MIN(IPAddress) works for 80% but still need also to have that 20% resolved.SELECT MachineId, Min(IPAddress) As IPAddress FROM @IPInfoGROUP BY MachineIdORDER BY MachineIdMachineId IPAddress1 143.1.96.292 143.34.96.03 155.119.212.2124 192.168.1.555 172.20.25.556 10.1.55.212 NOK (This should be the 155.119.232.22)7 192.168.2.55 NOK (This should be 192.44.55.212)Thx for all the help

Backup Automation

Posted: 20 Jun 2013 12:17 AM PDT

Hello Masters!We have more than 100+ instances across different SQL servers, and currently manually checking whether the backup job failed\success. Now we are planning to automate this monitoring. So need help to know how to know the specific backup job failed ? I little bit know that the backup information stored in system database "msdb", but dont know which table contains that information.Can anyone let me know what table contains that information ? Or what is the query to find out backup job's status ?

Truncate statement

Posted: 19 Jun 2013 09:32 PM PDT

Is it possible to rollback a Truncate statement?

[Articles] Lost in Space

[Articles] Lost in Space


Lost in Space

Posted: 19 Jun 2013 11:00 PM PDT

It seems a tremendous amount of data is lost every year on laptops in airports. Steve Jones talks about some of the issues with physical security and your portable computers.

[MS SQL Server] Why SQLCMD?

[MS SQL Server] Why SQLCMD?


Why SQLCMD?

Posted: 19 Jun 2013 05:59 AM PDT

Days by day i am learning something new in SQL Server. Before learning anything i want to understand why do we need this feature. This is the same case when i am learning SQLCMD.I would like to know what are the thing that can be done through SQLCMD which are not possible through SSMS.Or are there any advantages that while doing a certain set of task through SQLCMD.Thanks in advance.

Difference between ALTER TABLE REBUILD and rebuilding clustered index on that table

Posted: 20 Jun 2013 12:57 AM PDT

Hi all,After reading [url=http://rusanu.com/2011/10/20/sql-server-table-columns-under-the-hood/]this article[/url], I was wondering if there's a difference between using ALTER TABLE with the REBUILD option and rebuilding the clustered index on that table. BOL is not very extensive on the subject.Furthermore, I was wondering if it is necessary to check (and how? Counting and comparing columns from the sys.system_internals- and the sys.columns?) if you need to rebuild a table, because as I understand, a lot of space can get lost after performing DDL statements.Thanks in advance!- Alex

Upgradation of sql server

Posted: 19 Jun 2013 11:30 PM PDT

is there any issues to upgrade sql server from 2000 to 2008 ?and what is the better way to upgrade from 2000 to 2008 ?and can we restore system databases of sql server 2000 to 2008 and system databse of sql 2005 to 2008 ?

Automating the SQL Profiler

Posted: 19 Jun 2013 07:43 PM PDT

Hi All,I'm facing an issue while trying to automate the SQL Profiler run via scripts:Requirement:Need to audit few events on 24 hour basis /365 days for auditing purposeWhat I did:1) Started SQL Profiler and selected events as per my choice and stopped the trace...2) Scripted the profiler output and saved it as a stored procedure3) Called the SP through SQL Agent Job abd scheduled to run every 5 mins..Results:Except the first job run, rest all run fails...Can you please help me...Thanks..

MSSQLSERVER Services not start?

Posted: 19 Jun 2013 10:21 PM PDT

Hi,win - 2008 enterprise edtion SQL - SQL Server 2008 SQL SP -service pack 1windows application log found as below error messages, pl. suggestion me how to resolve this issues[code="other"]SQL Server could not spawn FRunCM thread. Check the SQL Server error log and the Windows event logs for information about possible related problems.Could not start the network library because of an internal error in the network library. To determine the cause, review the errors immediately preceding this one in the error log.TDSSNIClient initialization failed with error 0x57, status code 0x1. Reason: Initialization failed with an infrastructure error. Check for previous errors. The parameter is incorrect.TDSSNIClient initialization failed with error 0x57, status code 0x50. Reason: Unable to initialize the Named Pipes listener. The parameter is incorrect.Server named pipe provider failed to listen on [ \\.pipe\sql\query ]. Error: 0x57[/code]

Named Pipes vs TCP - Connection Errors

Posted: 19 Jun 2013 09:52 PM PDT

Hello,A bit of a strange one....and i swear this is a networking issue somewhere....but according to the networks team they cannot find anything.Wanted to know if anyone here can think of something to check and why the temporary workaround works!!---------------------We have a satellite office, connected by a high-speed dedicated link (not VPN) back to our corporate network. In this office are a couple of user PC's which use Crystal Reports to access a SQL database held in the datacentre. They have been experiencing issues with both Crystal Reports and using SSMS, and have been getting the error:[b]Error Number:121 Error Message:TCP Provider: The semaphore time-out period has expired.[/b]This will happen the second time they run the report or associated select query from SSMS....the first time it always works. If i log off and back on again it will also work....but any subsequent attempt fails.Through some investigation we found that this is the only occurence of this error so cannot be related to the database server itself. Moving the users PC into the main office (different subnet) resolves the issue. Moving an already working PC from the main office to the satellite office causes the issue to appear on that machine also.The workaround i found was to change the connection string to use Named Pipes. This allows the query and Crystal Reports to run successfully every time. I know it misses out the network stack (TCP) by using named pipes but for the life of me i cannot figure out exactly why this would work every time if there was a genuine network issue.All the forums on the internet and here just point people to the Microsoft networking investigation article. I have checked a number of the settings (TCP offload, TCP Chimney etc) and they are all disabled on the SQL Server. They are active on the user desktop though....but then again they are active on my desktop and i experience no issues.Without something definitive to help me explain to the networks team why the named pipes connection always works and why it is an intermittent issue....they will not help me!Many thanks

Dbcc checkdb command

Posted: 19 Jun 2013 06:23 PM PDT

Dear Sir,Here i am having a doubt When we run DBCC CHECKDB command if we found any error we can fix them by using repair_fat,Repair_rebuild,Repair_allow_data_loss.If application team not ready for data loss we will restore the backup.if they are not ready to restore the backup also is there any another method to fix this issue.

SQL server agent SSIS error

Posted: 19 Jun 2013 12:00 PM PDT

I get the following error when I execute my package as a SQL server agent job.It is an SSIS 2008 package running on a SQL Server 2008 instance. My package security is DontSaveSensitive.I don't even know how to begin fixing this error.Where should I check first?Date a value of timeLog Job History (MyJob)Step ID 1Server PCTSQL004Job Name MyJobStep Name Job_1Duration 00:00:00Sql Severity 0Sql Message ID 0Operator Emailed Operator Net sent Operator Paged Retries Attempted 0MessageExecuted as user: CS\DmcSysManager. The process could not be created for step 1 of job 0x63BB5A86DB23F947866D2A806BE4CC6B (reason: A required privilege is not held by the client). The step failed.

Clone users

Posted: 19 Jun 2013 09:45 AM PDT

I am using below query to get all the permissions of Old user. here my question is i am getting only database query in result set. i need script for all the databases.SET NOCOUNT ONDECLARE @OldUser sysname, @NewUser sysnameSET @OldUser = 'Old'SET @NewUser = 'New'SELECT 'USE' + SPACE(1) + QUOTENAME(DB_NAME()) SELECT '--Cloning permissions from' + SPACE(1) + QUOTENAME(@OldUser) + SPACE(1) + 'to' + SPACE(1) + QUOTENAME(@NewUser)SELECT 'EXEC sp_addrolemember @rolename =' + SPACE(1) + QUOTENAME(USER_NAME(rm.role_principal_id), '''') + ', @membername =' + SPACE(1) + QUOTENAME(@NewUser, '''') FROM sys.database_role_members AS rmWHERE USER_NAME(rm.member_principal_id) = @OldUserORDER BY rm.role_principal_id ASCSELECT CASE WHEN perm.state <> 'W' THEN perm.state_desc ELSE 'GRANT' END + SPACE(1) + perm.permission_name + SPACE(1) + 'ON ' + QUOTENAME(USER_NAME(obj.schema_id)) + '.' + QUOTENAME(obj.name) + CASE WHEN cl.column_id IS NULL THEN SPACE(0) ELSE '(' + QUOTENAME(cl.name) + ')' END + SPACE(1) + 'TO' + SPACE(1) + QUOTENAME(@NewUser) COLLATE database_default + CASE WHEN perm.state <> 'W' THEN SPACE(0) ELSE SPACE(1) + 'WITH GRANT OPTION' END AS '--Object Level Permissions'FROM sys.database_permissions AS perm INNER JOIN sys.objects AS obj ON perm.major_id = obj.[object_id] INNER JOIN sys.database_principals AS usr ON perm.grantee_principal_id = usr.principal_id LEFT JOIN sys.columns AS cl ON cl.column_id = perm.minor_id AND cl.[object_id] = perm.major_idWHERE usr.name = @OldUserORDER BY perm.permission_name ASC, perm.state_desc ASCSELECT CASE WHEN perm.state <> 'W' THEN perm.state_desc ELSE 'GRANT' END + SPACE(1) + perm.permission_name + SPACE(1) + SPACE(1) + 'TO' + SPACE(1) + QUOTENAME(@NewUser) COLLATE database_default + CASE WHEN perm.state <> 'W' THEN SPACE(0) ELSE SPACE(1) + 'WITH GRANT OPTION' END AS '--Database Level Permissions'FROM sys.database_permissions AS perm INNER JOIN sys.database_principals AS usr ON perm.grantee_principal_id = usr.principal_idWHERE usr.name = @OldUserAND perm.major_id = 0ORDER BY perm.permission_name ASC, perm.state_desc ASCthank you in advance.

how to manage memory for an sql server

Posted: 19 Jun 2013 08:27 AM PDT

I'd like now how to better understand the memory utilize by sql server. I have done some continues statistics and using monitoring tools and it seems that in some of my servers I see a constant high memory usage for both the OS and the SQL Server memory. In some instances the sql server memory reaches 95% and stays to that under for several hours.Any ideas where I can start reading and understanding what it all means and how to figure out what's causing the high memory usage?Thank you.

SQL server service pack for browser

Posted: 19 Jun 2013 08:16 AM PDT

In windows control-panel , uninstall and change a program, I see SQl server 2008 service pack 2 is installed, but also see there is a separate SQL server 2008 service pack 2 browser.I am going to apply service pack 3 to fix a SQL browser issue, I was told the SP3 will fix that.My question is by running SP3 will also upgrade SQl browser, correct?Thanks much

[SQL 2012] NUMA and PLE on SQL Server 2012

[SQL 2012] NUMA and PLE on SQL Server 2012


NUMA and PLE on SQL Server 2012

Posted: 04 Feb 2013 11:26 PM PST

I've read both Paul and Jonathan's blogs regarding this issue (http://www.sqlskills.com/blogs/paul/page-life-expectancy-isnt-what-you-think/) and started looking at the PLE counters for each individual NUMA node. I can't seem to wrap my head around why there is such a widespread discrepancy between the NUMA nodes. We are running SQL Server 2012 Enterprise Core. Any insight would be greatly appreciated.Thanks,Tommy[url=https://skydrive.live.com/redir?resid=EB98D18648791013!7197&authkey=!AN6DKRDzgyJlarU]https://skydrive.live.com/redir?resid=EB98D18648791013!7197&authkey=!AN6DKRDzgyJlarU[/url][img]https://skydrive.live.com/redir?resid=EB98D18648791013!7197&authkey=!AN6DKRDzgyJlarU[/img]

Deploying report to server

Posted: 20 Jun 2013 01:26 AM PDT

Hi, I'd like some advise on deploying a report to a server where the datasource is on a separate server.I'm currently creating the report on my local machine, which is using SQL 2012 Data Tools. The database is hosted on a SQL 2005 Server. I'm deploying to a SQL 2012 Server. All on same domain, etc.I'm currently getting an error when accessing the report via a browser: An error has occurred during report processing. (rsProcessingAborted) Cannot create a connection to data source 'DataSource1'. (rsErrorOpeningConnection) For more information about this error navigate to the report server on the local server machine, or enable remote errorsWhen I access the log I see:library!ReportServer_0-8!5bec!06/20/2013-15:17:07:: w WARN: Microsoft.ReportingServices.ReportProcessing.ProcessingAbortedException: An error has occurred during report processing. ---> Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: Cannot create a connection to data source 'DataSource1'. ---> System.Data.SqlClient.SqlException: Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.I've previously successfully made reports where the database was on the same server as the reporting server, but never tried it this way. Any tips?

RESTORE DATABASE is terminating abnormally.

Posted: 19 Jun 2013 09:28 PM PDT

Hi there, I have a database called - Oneserve_Stage, which for some reason is showing as (Restoring...) next to the database.How can I get this back to a normal state.When I run the following TSQL - USE masterRESTORE DATABASE [Oneserve_Stage] FROM DISK = N'\\mhsvi-mgmt03\oneserve_DW\ExportFromOneserve\MHS_DataCut_PROD.BAK' WITH FILE = 1, RESTART, RECOVERYI get the following errors - Msg 3183, Level 16, State 2, Line 2RESTORE detected an error on page (0:0) in database "Oneserve_Stage" as read from the backup set.Msg 3013, Level 16, State 1, Line 2RESTORE DATABASE is terminating abnormally.I have no idea why this database is now showing like this? Any help will be appreciated.Thanks

Any way to display multiple rows of tabs?

Posted: 19 Jun 2013 11:55 PM PDT

SSMS 2012: when you open up many sql files in the IDE, it starts hiding some tabs and you have to click on the drop down at the right to navigate to the tab you want. Is there a way to make it display more than one row of tabs, so that tabs are not hidden and always displayed?

SSRS 2012 color theme

Posted: 19 Jun 2013 07:14 AM PDT

Can it be changed? Not the text editor window and fonts, but rather the toolbars and empty environment colors. I hate the default blue color.

SQL Server Management Studio and TFS

Posted: 19 Jun 2013 10:40 PM PDT

Hello, I am running SSMS 2012 SP1 and Visual Studio 2012 on my computer and Team Foundation Server works fine within VS but not SSMS. Under Tools>Options>Source Control in SSMS, there are no plug-ins listed, but they are in VS. Any ideas on what I need to do to make TFS work with SSMS?

[T-SQL] convert int int to date urgent please

[T-SQL] convert int int to date urgent please


convert int int to date urgent please

Posted: 20 Jun 2013 12:18 AM PDT

/****** Script for SelectTopNRows command from SSMS ******/SELECT TOP 1000 [ServerName] ,[IsExisting] ,[IsEnabled] ,[IsScheduleEnabled] ,[NAME] ,CONVERT(date, CONVERT(VARchar(18), LASTRUNDATE)) ,[Date] FROM [Monitor].[dbo].[Job_Monitor] plz need it urgent lastrundate is int (20130620)format need to convert to date 2013/06/20error :::Msg 241, Level 16, State 1, Line 4Conversion failed when converting date and/or time from character string.

UPDATE, MERGE or table-valued function UDF?

Posted: 19 Jun 2013 09:11 AM PDT

Hi,I'm confused how to solve this:Using UPDATE, MERGE, table-valued UDF or what?:w00t:I know using a cursor is possible but there are disadvantages...tblA [code="plain"]colA1 colA2 colA3=======================C 15 NULLD 17 NULL G 18 NULL L 19 NULL R 20 NULL [/code]tblB (the lookup table) [code="plain"]colB1 colB2 col3=======================28 15 134 17 135 18 136 18 037 18 042 19 143 20 044 20 1[/code]To do:Find in tblB the lines with col3 = 1 (exists only once for same colB2-value), Then UPDATE tblA colA3 with value colB1. RI exists on colB2 = colA2

Interesting Question related to Splitting table row conditionally

Posted: 19 Jun 2013 10:47 PM PDT

Hi SQL Addicts,Please help! Its emergencyThe Table setup is as followsCREATE TABLE dbo.Receipt(ReceiptID int NOT NULL IDENTITY(1,1), PolicyID int NOT NULL, ReceiptAmt NUMERIC(17,2) NOT NULL)GOINSERT INTO dbo.Receipt(PolicyID, ReceiptAmt)SELECT 11, 3000UNION ALLSELECT 11, 5000UNION ALLSELECT 11, 1200GOCREATE TABLE dbo.MemberPremiumDet(MemberID int NOT NULL IDENTITY(1,1), PolicyID int NOT NULL, PremiumAmt NUMERIC(17,2) NOT NULL)GOINSERT INTO dbo.Receipt(PolicyID, PremiumAmt)SELECT 11, 1200UNION ALLSELECT 11, 1600UNION ALLSELECT 11, 2200UNION ALLSELECT 11, 2456UNION ALLSELECT 11, 1144GOReceipt Table DataPolicyID ReceiptID ReceiptAmt11 1 300011 2 500011 3 1200Member DataPolicyID MemberID PremiumAmt11 1 120011 2 160011 3 220011 4 245611 5 1144With the above given two tables the below output to be generated without using Cursors or loopsI Want the output as followsMemberID ReceiptID ReceiptAmt ConsumedAmt BALAmt171 11 3000 1200 1800172 11 1800 1600 200173 11 200 200 0173 14 5000 2000 3000174 14 3000 2456 544175 14 544 544 0175 16 1200 600 600Thanx in advance!!!

pivot? can't make it work.

Posted: 19 Jun 2013 09:05 PM PDT

Hi there, I'm hoping for a pointer in the right direction as I can't suss this out & feel that it shouldn't be that complicated.I have a table id characteristic value(nvarhcar)1 color blue1 age 51 gender female2 color green2 cost 53 desc blahblah3 lastcheck 27/jan/093 ... 3 ...Client wants output as follows:id characteristic1 value1 characteristic2 value2 ... 1 color blue age 2 color green desc blah There is no aggregate.Ideally query would by dynamic as new characteristics values may be added. not all id's have same number of characteristic values.does this make sense?any ideas / pointers gratefully accepted?thanks.

Strange issue with sp_OAMethod

Posted: 19 Jun 2013 08:51 PM PDT

My procedure creates a COM object with sp_OACreate. Then it uses the sp_OAMethod to call a "load" method of the underlying DLL. Finally it uses sp_OADestroy to dispose the COM object.The procedure works perfectly fine the first round.During the second round of execution, sp_OACreate succeeds. But sp_OAMethod returns insufficient memory error. I was under the impression that sp_OADestroy would have released the memory, but that doesn't seem to be the reality.I tried the following commands after the first round of executionDBCC DROPCLEANBUFFERSDBCC FREEPROCCACHEDBCC FREESESSIONCACHEDBCC FREESYSTEMCACHE ('ALL')But none of them (nor all of them together) help.The only way out is to restart the SQL Service after each round of execution.Is there a way around this?

Append characters in a sentence after certain length

Posted: 19 Jun 2013 03:21 AM PDT

Hi,Need your help in accomplishing this one. We run on SQL Server 2008. I've a string that can be upto 200 characters max and after every 32 characters a pile (|) got to be inserted. if that 32 characters come in midword, then that pipe has to be placed in the beginning of that word, not in the middle of the word. Example:Original String: ABCDEFGH IJKLMNOPQRS TUVWXYZ ABCDEFGHIJKLMN OPQRSTUVWXYZA BCDEFGHIJKLMNOPWant this way: ABCDEFGH IJKLMNOPQRS TUVWXYZ |ABCDEFGHIJKLMN OPQRSTUVWXYZA |BCDEFGHIJKLMNOPsince these strings are in a table.column and this need to operate on the entire data set (about 200k records), performance is also important.thanks in advance..

compare all tables and find number of common columns between all tables

Posted: 19 Jun 2013 03:05 PM PDT

is there any way to compare every table with each other in a database list the number of common column between each tables!! ?? prefer using join over subquery and information_schema.column, if possible thx. example: lets say there are 4 tables in a database table1, table2, table3 and table4.list1 list2 commonColumns ----- -------- --------------------table1 table2 1table1 table3 2table1 table4 0table2 table1 1table2 table3 5table2 table4 2table3 table1 3 table3 table2 0table3 table4 1table4 table1 2table4 table2 3table4 table3 0this is what i have got so farselect c1.table_name,c2.table_name,c1.COLUMN_NAMEfrom information_schema.columns c1JOIN information_schema.columns c2 ON c1.column_name= c2.column_name where c2.table_name <> c1.table_name and c2.column_name = c1.column_nameORDER BY c1.table_name, c2.TABLE_NAME

Non cluster index help (SSMS 2008 R2)

Posted: 19 Jun 2013 05:02 PM PDT

Hi Friends,I have table (Table_A (A_id int(PK), col1 nvarchar, col2 nvarchar, col3 nvarchar, col4 nvarchar, col5 nvarcarCol6 nvarchar))A_id int(PK),--- already have one clusterd index on this column as this is PKI hav only ONE non clustered index on col1, col2 and col3 and i have below querySELECT col4, COl5, col6FROM Table_A a INNER JOIN Some_Table_B bON a.a_id = b.b_some_idWHERE a. col1 = 'Some value' AND a.col2 = 'some Value' and a.col3 = 'SOme value'**Question 1** do i need more NON Clustered index on this table so that, this query will perform well(as SELECT statement has more columns which dont have any indexex, ). **Question 2**if i put the non clusterd index on the columns which are only considerd for displaying the result set(example, here col4, COl5, col6 with SELECT only, these columns are not utilised in WHERE or JOIN clause ) WIll this improve performance of the query **Question 3**Another question (as as i have mentined earlier NON clustred index is on col1, col2 and col3 )if my WHERE clause hav only col_1 and col_2 ,Example SELECT col4, COl5, col6FROM Table_A a INNER JOIN Some_Table_BON a.a_id = b.b_some_idWHERE a. [b]col1 [/b]= 'Some value' AND a.[b]col2 [/b]= 'some Value' --- no column3 okwill this non cluster index help or do i need to create another index only with these two columns.Please do the needful.**Thanks in AdvanceParixitsinh**

How to create the Dynamic Table...

Posted: 19 Jun 2013 04:45 AM PDT

Hi Friends,I have the sample data for the following Structure[code="sql"]Create Table PivotA ( IDT int,A int,B int)insert into PivotA values (24,1,-1),(24,2,-2),(24,3,-3),(24,4,-4),(25,5,-5),(25,6,-6),(25,7,-8),(26,8,-8),(26,9,-9),(26,10,-10)select * from PivotA[/code]but i need to create the tables dynamically for the following structure..based on the PivotA Table...[code="sql"]create table IDT_24( A int,B int)insert into IDT_24 values (1,-1),(2,-2),(3,-3),(4,-4)create table IDT_25( A int,B int)insert into IDT_25 values (5,-5),(6,-6),(7,-8)create table IDT_26( A int,B int)insert into IDT_26 values (8,-8),(9,-9),(10,-10)select * from IDT_24select * from IDT_25select * from IDT_26[/code]How To Get it?any one help me...Thanks & RegardsK.D.Saravanan

[SQL Server 2008 issues] How to find when my SSRS service was last restarted ?

[SQL Server 2008 issues] How to find when my SSRS service was last restarted ?


How to find when my SSRS service was last restarted ?

Posted: 19 Jun 2013 06:38 PM PDT

Expertrs,How to find when my SSRS service was last restarted ? Not the DB Engine.. Only Reporting services..Thanks in advance..Smith.

How to get user position in table i.e 1st 2nd, 3rd

Posted: 19 Jun 2013 07:09 PM PDT

hello,Im having a bit of trouble trying to return the current users position, iv been looking at this for the past 3 days browsed many forums tried many situations but with still no luck.I have a table called prospectlead which has a column called ReviewedBy this gets populated when the user checks a record etcthe desired output would be 1st John2nd Me3rd Sarah This will obviously change throughout the day depending on how the individuals get on, so mid morning i could go from 2nd position down to 10th but i need to return my position plus the person above me and the person below me, the way im getting the amount of records checked is by using a COUNT, the parameter passed in to the stored procedure is the ShortAbbr which would be 'D13' (again thats hard coded to get it working, it would actaully be @ShortAbbr passed in from the front end)Can any one help me on this please?[code="sql"]Select ROW_NUMBER() over(order by u.UserID) as RowNumber, count(p.ID) as TotalCount, u.Firstname + ' ' + u.Surname as DataCheckerfrom ProspectLead p join UserAccount u on p.reviewedby = u.ShortAbbrwhere p.ReviewedBy is not null and convert(date, p.ReviewedDate) = convert(date, SYSDATETIME())and u.Responsibility = 16and u.ShortAbbr = 'D13'group by u.Firstname, u.Surname, u.UserID order by TotalCount desc[/code]

How to print a file using a static ip and a printer name

Posted: 19 Jun 2013 05:21 PM PDT

How to print a file using a static ip and a printer name.Plz help me

Rows to Columns (pivot or anyother way)

Posted: 19 Jun 2013 07:07 AM PDT

Hi am trying to change row values to column based on ControlNO & Seq column. (Please see @currenttable)InspInterval --> int0,int1,int2,int3ChkProcedureKey --> p_chkproc0,p_chkproc1,p_chkproc2,p_chkproc3IntUnit --> intunit0,intunit1,intunit2,intunit3I did try to do pivot but was unsuccessful :-(Included is the sql of what the table looks like currently and how I has to be converted.. FYI, they are 208503 records in the table if that matters on the method we look into.[code="sql"]Declare @CurrentTable Table([ControlNo] [nvarchar](15),[MODELKEY] [int],[SEQ] [bigint],[InspInterval] [int],[ChkProcedureKey] [int],[IntUnit] [nvarchar](1)) INSERT INTO @CurrentTableselect '020468','7996','1','2','99','Y' UNIONselect '020468','7996','2','6','26','M' UNIONselect '020468','7996','3','6','27','M' UNIONselect '020468','7996','4','12','28','M'UNIONselect '03020/51001048','12307','1','0','99','M' UNIONselect '03020/51001048','12307','2','0','363','M'UNIONselect '03020/51001048','12307','3','0','364','M'SELECT * FROM @CurrentTableDeclare @RequiredTable Table ([ControlNo] [nvarchar](15),[MODELKEY] [int],[int0] [int],[int1] [int],[int2] [int],[int3] [int],[p_chkproc0] [int],[p_chkproc1] [int],[p_chkproc2] [int],[p_chkproc3] [int],[intunit0] [nvarchar](1),[intunit1] [nvarchar](1),[intunit2] [nvarchar](1),[intunit3] [nvarchar](1)) INSERT INTO @RequiredTableselect '020468','7996','2','6','6','12','99','26','27','28','Y','M','M','M' UNIONselect '03020/51001048','12307','0','0','0','','99','363','364','','M','M','M',''SELECT * FROM @RequiredTable[/code]

Running Totals

Posted: 19 Jun 2013 10:37 AM PDT

I am having problems figuring out how to add a running total. I initially tried to get my TempTable to show the different categories of transactions by reporting 1, 2, or 3. I could not get my program to do this. I ultimately want curItem compared to prevItem and if there is not a match, to populate the Trnd field with 1. If the curItem and prevItem match, I need the program to incrementally sum from the first mis-match to the end of the matched fields. [code="sql"]--===== If the test table already exists, drop it IF OBJECT_ID('TempDB..#mytable','U') IS NOT NULL DROP TABLE #mytable--===== Create the test table with CREATE TABLE #mytable ( curItem char, prevItem char, Trnd int ) INSERT INTO #mytable (curItem, prevItem, Trnd)SELECT 'D', 'U','' UNION ALLSELECT 'D', 'U','' UNION ALLSELECT 'U', 'D','' UNION ALLSELECT 'U', 'U','' UNION ALLSELECT 'U', 'U','' SELECT *FROM #mytableDECLARE @TempTable TABLE (curItem char(2), prevItem char(2), Trnd int);DECLARE @curItem char(2), @prevItem char(2)INSERT INTO @TempTable(curItem, prevItem, Trnd)SELECT curItem, prevItem, TrndFROM #mytableBEGIN SELECT @curItem = curItem, @prevItem = prevItem FROM @TempTable IF @curItem = @prevItem BEGIN UPDATE EURUSD#1A SET Trnd = 1; END ELSE IF @curItem <> @prevItem BEGIN UPDATE EURUSD#1A SET Trnd = 2; END ELSE BEGIN UPDATE EURUSD#1A SET Trnd = 3; END SELECT * FROM @TempTableEND [/code]

How you take the breakup by each component in Multi_Pages ( Otherwise MTL/NonBpool )

Posted: 19 Jun 2013 02:34 PM PDT

Question : How you take the breakup by each component in Multi_Pages ( Otherwise MTL/NonBpool )like: SQLMailOle ComponentsLinked ServerThird Party DLL'sExtended SP'sCLR

Security Material.

Posted: 19 Jun 2013 04:09 PM PDT

Hi all, Can any one refer some web pages or books related to security part of SQL. I am struggling to understand the concept of schema,principles,permissions,users having schema and etc.......giving permissions to particular table.

SQL server agent SSIS error

Posted: 19 Jun 2013 11:39 AM PDT

I get the following error when I execute my package as a SQL server agent job.It is an SSIS 2008 package running on a SQL Server 2008 instance. My package security is DontSaveSensitive.I don't even know how to begin fixing this error.Where should I check first? Date a value of timeLog Job History (MyJob)Step ID 1Server PCTSQL004Job Name MyJobStep Name Job_1Duration 00:00:00Sql Severity 0Sql Message ID 0Operator Emailed Operator Net sent Operator Paged Retries Attempted 0MessageExecuted as user: CS\DmcSysManager. The process could not be created for step 1 of job 0x63BB5A86DB23F947866D2A806BE4CC6B (reason: A required privilege is not held by the client). The step failed.

Run inserts from file with many records

Posted: 19 Jun 2013 06:54 AM PDT

Hi!I need to run inserts from file with many records/rows: about 500.000.My Management Studio is not supporting many records, there is a memory error.Is there any way to break up the files into parts , or [b]read via cmd[/b] ?Thanks!Jose Anchieta C. Jr

Restoring from the backup after encryption of datbase

Posted: 19 Jun 2013 03:07 AM PDT

Hi friends,I used the following query to restore the encrypted database.USE master;GOCREATE DATABASE Encry2ON ( NAME = Encry2_dat, FILENAME = 'D:\SQL2008R2DB\MSSQL10_50.SQL2008R2\MSSQL\Backup\TDEPost.mdf', SIZE = 3, MAXSIZE = 5, FILEGROWTH = 1 )LOG ON( NAME = Encry2_log, FILENAME = 'D:\SQL2008R2DB\MSSQL10_50.SQL2008R2\MSSQL\Backup\TDEPost2Log.ldf', SIZE = 1MB, MAXSIZE = 5MB, FILEGROWTH = 1MB ) ;GOopen MASTER KEY DECRYPTION BY PASSWORD = 'password';RESTORE DATABASE Encry2 FROM DISK = N'D:\SQL2008R2DB\MSSQL10_50.SQL2008R2\MSSQL\Backup\TDEPost.bak' WITH FILE = 1, MOVE N'mydb' TO N'D:\SQL2008R2DB\MSSQL10_50.SQL2008R2\MSSQL\Backup\TDEPost.mdf', MOVE N'mydb_log' TO N'D:\SQL2008R2DB\MSSQL10_50.SQL2008R2\MSSQL\Backup\TDEPost.ldf', NOUNLOAD, REPLACE, STATS = 10CLOSE MASTER KEYIt gives me following error message[b]Msg 3234, Level 16, State 2, Line 2Logical file 'mydb' is not part of database 'Encry2'. Use RESTORE FILELISTONLY to list the logical file names.Msg 3013, Level 16, State 1, Line 2RESTORE DATABASE is terminating abnormally.[/b]My concern is I want to show that , I encrypted the database.I already show that both the backup files , one gereted before the backup and one after are totally different in terms of size and also the content.Now, I need to show what kind of problem one can get if he/she restore the backup file which I have created after encryption.!!do they need password of master key.?how one can restore the encrypted database backup file other than me ?please help.thanks.

SQL grouping question

Posted: 19 Jun 2013 04:35 AM PDT

sorry for the nature of the question, I just don't know how to write this query. I have 2 tables, one is a user table and the other is phone data from my phone system, I am just trying to write a query to join the 2 tables together where I can get the user (fullname) from the User_data table to join each users from the phone column to both the callingparty and calledparty field from the CDR_Data table. Basically all the records from the CDR_Data table where both the callingparty field and the calledparty field are joined to the phone column on the User_data table so I can see both types of calls for each user. Any help is appreciated, thanks! My 2 tables are as follows:CDR_DataIDDatetimeorigination (datetime)callingparty (int)calledparty (int)datetimeconnect (datetime)datetimedisconnect (datetime)duration (int)User_datafullname (char)phone (int)

how to get person with multiple rates

Posted: 19 Jun 2013 05:50 AM PDT

I have a scenario where a single client can have multiple workers with either all workers having same rate or each worker having different rates for the same participant,sample data is as belowworker client ratefrank derek 0.55sandra derek 0.55saeed haleema 0.555curtis julia 0.555marilyn julia 0.55jane william 0.555adam william 0.55lisa anderson 0.555marketa pamela 0.55Now i need to get the list of clients and workers who have different rates like for example result should be curtis julia 0.555marilyn julia 0.55jane william 0.555adam william 0.55

How will work with(nolock) option in select queries

Posted: 19 Jun 2013 03:10 AM PDT

Hi,We have few transaction tables having more than 20 million rows and using those table when we select tables are blocking and we are getting deadlocks, those tables are well indexed and well maintained. can we use WITH(NOLOCK) option in select queries for these tables. how it will work. please do me needful.Regards,BSL

Need column name if condition fails

Posted: 19 Jun 2013 02:42 AM PDT

Hi All,I need to write a code in SQL Server 2008 in which I have 4 columns(First Name (2 columns) and Last Name (2 columns)).I have a 5th column name 'Status'.I have set a condition that if value in 1st and 3rd column [First Name]and 2nd & 4th column [Last Name] matches the status is shown TRUE else FALSE.But I have been told to write Column name where discrepancy is present, instead TRUE or FALSE.Can anyone guide me regarding this?I am just a beginner in this field.

Need column name in Status column

Posted: 19 Jun 2013 02:45 AM PDT

Hi All,I need to write a code in SQL Server 2008 in which I have 4 columns(First Name (2 columns) and Last Name (2 columns)).I have a 5th column name 'Status'.I have set a condition that if value in 1st and 3rd column [First Name]and 2nd & 4th column [Last Name] matches the status is shown TRUE else FALSE.But now I have been told to write Column name even if the data is matching or if it has discrepancy, instead TRUE or FALSE.Can anyone guide me regarding this?I am just a beginner in this field.

SSIS Using XML Source and max size limit of nvarchar(4000)

Posted: 19 Jun 2013 01:43 AM PDT

I have xml files that I'm trying to import into SQL Server using SSIS XMLSource and the xml file has a field that contains more that 4000 bytes. I think the maximum is 4000. I'm defining this in the external and output column area of the XML Source Show Advance Source Editor. Any ideas how to get around this problem?

SSIS Package Fails - Unhelpful Error message

Posted: 19 Jun 2013 02:36 AM PDT

We have a job that gets data off a website and imports into SQL. It runs for a couple hours, then fails with the following message. Not very helpful.".. This error occurs when the server is experiencing problems..."Any thoughts, or am I missing something ? (not the first time)[code="plain"]Microsoft (R) SQL Server Execute Package UtilityVersion 10.0.2520.0 for 32-bitCopyright (C) Microsoft Corp 1984-2005. All rights reserved.NULLStarted: 07:00:42Error: 2013-06-19 09:36:35.18 Code: 0xC001600E Source: MRIFeed Connection manager "Job" Description: Server returned status code - 500 : Internal Server Error. This error occurs when the server is experiencing problems.End ErrorError: 2013-06-19 09:36:35.23 Code: 0x00000001 Source: Download job XML Description: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Microsoft.SqlServer.Dts.Runtime.DtsRuntimeException: Server returned status code - 500 : Internal Server Error. This error occurs when the server is experiencing problems. ---> System.Runtime.InteropServices.COMException (0xC001600E): Server returned status code - 500 : Internal Server Error. This error occurs when the server is experiencing problems.NULL at Microsoft.SqlServer.Dts.Runtime.Wrapper.IDTSHttpClientConnection100.DownloadData() at Microsoft.SqlServer.Dts.Runtime.HttpClientConnection.DownloadData() --- End of inner exception stack trace --- at Microsoft.SqlServer.Dts.Runtime.HttpClientConnection.DownloadData() at ST_986b2264c6724ec5b4336f7799acb425.vbproj.ScriptMain.Main() --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture) at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()End ErrorDTExec: The package execution returned DTSER_FAILURE (1).Started: 07:00:42Finished: 09:36:35Elapsed: 9352.84 secondsNULL[/code]

Transaction log and Full backups are not happening on secondary & DR

Posted: 19 Jun 2013 02:05 AM PDT

Hi every one,My title shall give you all information.I am not able to see any kind of logs getting recorded when i perform them by using a scheduled job.Even though the logs are not recorded. I couldnot see any kind of error msg inspite shows success.But if i do them manually they does get recorded.Is it normal.. What am i supposed to do.???NOTE: ROOKIE HERE :hehe:

Tempdb

Posted: 19 Jun 2013 12:07 AM PDT

Hi I need some clarification on this topic.what is tempdb mdf files used for vs ldf files used for?I understand tempdb mdf needing space and ldf not being used.In the event of ldf being used, what would this be used for?

Hai all

Posted: 19 Jun 2013 01:44 AM PDT

TITLE: Microsoft SQL Server Management Studio------------------------------Restore failed for Server 'RAJESH-PC\NAIDU'. (Microsoft.SqlServer.SmoExtended)For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1617.0+((KJ_RTM_GDR).110422-1125+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Restore+Server&LinkId=20476------------------------------ADDITIONAL INFORMATION:System.Data.SqlClient.SqlError: The operating system returned the error '5(Access is denied.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\AdventureWorksDW.mdf'. (Microsoft.SqlServer.Smo)For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1617.0+((KJ_RTM_GDR).110422-1125+)&LinkId=20476------------------------------BUTTONS:OK------------------------------what i have done so far is, fullbackup and transactional backup to disk 'D' and has given administrative permission to that folder and service account is NT AUTHORITY.Can anybody please help me out.Thanks in advance

Find the correct answer in the following query

Posted: 18 Jun 2013 10:48 PM PDT

Hi,I have two tables named customer and salesorder.In the customer table i have 1000 customers,Of which 900 customers have orders in the salesorder table.i execute the following query to list all customer sthat have had at least one sale.Select * from customer where customer.CustomerID in (Select Customer.CustomerID from salesorder)you need to identify the result of the query? which result will the query return?1) No rows2) A Warning message3) The 100 rows in the customer table4 The 900 rows in the customer table with matching rows in the salesorder table.I am thinking the answer is 4 but some are telling that the answer is 3.So can you plese tell me the correct answer with explanation.Thank you

Leave

Posted: 18 Jun 2013 09:49 PM PDT

i use this syntax in sql serverwhen t.timein is null and l.date is not null then u.description and make join like thisFROM attend_log) tleft join leaveinformation l on t.eid = l.eid and t.date = l.dateleft join leavedescription u on l.lid = u.lidbut its not giving me the desired resultits giving me that resultdate-----------------------------eid---------timein-----timeout---spendtime---remarks--2013-01-07 00:00:00.000--17074---------NULL-------NULL--------NULL------ABSENT i want this type of resultdate-----------------------------eid---------timein-----timeout---spendtime---remarks--2013-01-07 00:00:00.000--17074---------NULL-------NULL--------NULL------casual leave i join these tables[LeaveDescription]([LID] [int], <---------leave id[Description] [varchar](50) <------------leave description) [LeaveInformation]([CID] [int] NULL, <-----------company id[BID] [int] NULL, <------------branch id[EID] [int] NULL, <------------employee id[Date] [datetime] NULL,[LID] [int] NULL <-------------leave id) [ATTEND_LOG]([EID] [int] NULL,<------------employeeid[date] [datetime] NULL,[timein] [datetime] NULL,[timeout] [datetime] NULL,[BID] [int] NULL, <------------------branch id[EBID] [int] NULL,<--------------------employee branch id[spendtime] [datetime] NULL,[excessshort] [datetime] NULL,[excess] [nvarchar](50) NULL)if there is a data in leave information table then it shows like thisdate-----------------------------eid---------timein-----timeout---spendtime---remarks--2013-01-07 00:00:00.000--17074---------NULL-------NULL--------NULL------casual leave other wise shows like thisdate-----------------------------eid---------timein-----timeout---spendtime---remarks--2013-01-07 00:00:00.000--17074---------NULL-------NULL--------NULL------ABSENT

EMERGENCY MODE

Posted: 18 Jun 2013 10:05 PM PDT

HI ALL, I am experimenting with one of my test databases . I intentionally set the database to emergency mode.But now it is not coming out from that mode. I tried dbcc but it doesn't print any errors. Any one has any alternatives solution for this.

Restore Database if Job fails

Posted: 18 Jun 2013 09:44 PM PDT

HiIs there a way of starting a database restore if an agent job fails?Thanks

SQL Server 2008 view Query

Posted: 18 Jun 2013 08:53 PM PDT

Kindly help on sql query to create a view that merges data from two tables with same columns but second table (sales) has missing rows that correspond first table(Inventory) In essense: I need those items that are in Inventory table but don't have entries in sales table to be included in my sales view with (0) quantities. Inventory ItemID ItemName Qty 1 Bread 5 2 Soda 10 3 Cocoa 4 4 Blueband 15 5 Omo 20 6 Biscuits 30 7 Pens 50 8 Note book 5 Sales ItemID ItemName Qty 1 Bread 3 2 Soda 5 5 Omo 10 6 Biscuits 15 8 Note book 2 I want my sales view to look like below Sales View ItemID ItemName Qty 1 Bread 3 2 Soda 5 3 Cocoa 0 4 Blueband 0 5 Omo 10 6 Biscuits 15 7 Pens 0 8 Note book 5

log shipping version.

Posted: 18 Jun 2013 08:13 PM PDT

Hello All,Please let me know is it possible to create log shipping between two instances with different sql server version.Regards

Search This Blog