Wednesday, March 6, 2013

[SQL Server] Stuck on new fault with my update

[SQL Server] Stuck on new fault with my update


Stuck on new fault with my update

Posted: 06 Mar 2013 10:57 AM PST

Hi Professionals I am running the following query as advised previously which updates the source table based on a column from the reference table matching...BEGIN TRANSACTION Inner1;GOUPDATE dbsource SET software_name_raw = dbref.software_name_amended FROM dbo.BigTable dbsourceINNER JOIN ( SELECT software_name_raw,software_name_amended FROM RefTable GROUP BY software_name_raw,software_name_amended) dbref ON dbref.software_name_raw = dbsource.software_name_rawgoCOMMIT TRANSACTION Inner1;I have run into a problem which is. If they dont match I need to update the reference tables 2 columns with the new unmatched record to reference something like thisELSE INSERT INTO RefTable(software_name_raw,software_name_amended)Values BigTable(software_name_raw,'Needs Updating')How can or can this be amended easily.

Command(s) completed successfully. only output set parseonly NOT checked

Posted: 06 Mar 2013 04:18 AM PST

Hello,I have been trying to solve this for hours. I know it's very likely something really basic but...When I run a built in stored procedure, for example sp_helppublication, in SSMS, I just see this:Command(s) completed successfully.No output. I have checked so many settings. I think I have looked everywhere in the settings for SSMS but maybe not. I definitely don't have the set parseonly checked. Could someone please help? Thanks in advance.

The SSIS package keeps forgetting the password

Posted: 06 Mar 2013 03:57 AM PST

I have a SSIS Package that is giving me an error connection'Test connection failed because of an error in initializing provider. Login failed for user.....The package does not remember password.Im connecting to a SQL Server 2005 box using its user_password with sysadmin role.The SSIS package runs fine when you first set up the connection in bidsThe bottom line is that SSIS keeps forgetting the password I feed intothe two Connections that I'm using. I double-click a connection,type the password in, check "Save my password" and hit "OK" but thepassword disappears from there whenever I run the package ordouble-click the connection again.Is anyone know what to do!! please help!! I have a very short time to deploy this package in production.

combine multiple rows into one dynamically query question

Posted: 02 Sep 2009 05:20 AM PDT

Hi, I have the below table, and I need to combine theminto one records dynamically (I'm not sure I'm clear on this,so maybe you look at the below table is better).create table Test( id int, name varchar(30), counts int)insert into Testselect 1, 'Math', 5unionselect 1, 'Literature', 3unionselect 1, 'Cooking', 1unionselect 1, 'Reading', 2I would like the result to look like this below, id categorycounts1 Cooking (1), Literature (3), Math(5), Reading(2) the challenge I have is the id can have multiple values like this, how do I know to combine them all dynamically and correctly. thanks a lot if you could help and give any input.

Splitting a string into fields

Posted: 06 Mar 2013 12:46 AM PST

Hi AllI have a field called Defects which contain strings like the following. The string makeup is always the same.Scrap : Part Assembly : Surface Defects : ScratchScrap : Part Assembly : Components : Wrong ComponentsScrap : Part Assembly : Other : Change OverRepair : Punching : Surface Damages : CrackWhat I would like to do is create a view that splits the string by the : and have them displayed as individual fields.I started of using CharIndex to find the : and then use left and the charindex to strip the first part out, but I felt doing it this way would involve a lot of LEFTs and RIGHTs to split up the whole string, is there an easier way to accomplish this?CheersDJ

The absolute basics of coding SQL Server in VB.net

Posted: 05 Mar 2013 07:56 PM PST

I am trying my best to get my head around SQL Server but seem to be going around in circles. Everything I google is either way too complicated for my simple means or else I find half a dozen different ways to do the same thing.Can somebody please point me to a site, an article or a video where, in clear, plain, simple English, it explains the differences and the relationships between a datatable, a dataset, a dataadapter, a datastream & various other options I keep getting presented with ?!?The sooner I can grasp the concepts and the differences, the sooner I can spend my time actually coding rather than asking questions ;-) !!!

Invalid precision value

Posted: 05 Mar 2013 07:42 PM PST

Hi,I am new to MS SQL and the project need arose to bind an OUTPUT blob. Towards that I created a stored procedure which returns a nvarchar(max) type. I do not know what will be the length of this blob as this is constructed by the stored procedure.The SQL Server that I am running this on is 2005.I am binding in my C++ application using SQLBindParameter. This is how I am doing it. retcode = SQLBindParameter(hStmtHandle, output_blobs_[i].cur_pos, SQL_PARAM_OUTPUT, SQL_WCHAR, SQL_WLONGVARCHAR, 0, 0, (SQLPOINTER)output_blobs_[i].cur_blob, 0, (SQLINTEGER*)&size );This is how my stored procedure looks likecreate proc ujo_delete_box @del_dep_list nvarchar(max) OUT, @job_name varchar(64), @joid int, @rstr_del_job int, @rstr_del_depjob int, @ref_integrity int, @stamp int, @del_box int, @user varchar(80)No matter what I do I don't seem to get past the bind stage. With the way SQLBindParamter is depicted, I always end up with the below error when I try to bind the nvarchar(max) field. Error from SQLBindParameter() Failed for stored procedure. SQLSTATE: HY104, Native error: 0, Message: [Microsoft][ODBC SQL Server Driver]Invalid precision valuePlease let me know what am I doing wrong.Regards,Rajesh

Patching OS for SQL Boxes Advice

Posted: 05 Mar 2013 08:21 PM PST

Hi all, Anyone have any advice for patching windows on SQL boxes. We have dev environments for about 50% of our live servers. So will patch dev confirm its ok then live (They should be the Same OS, SQL version) I was just planning on doing all high priority updates and leaving software, where its windows search or IE etc. The thing im really not sure on about is .NET, IF SQL needs 3.5 to install should i ignore .NET 4? or upgrade to it? There always seems to be a lot lo .NET patches. so im interested to know what poeple normally do about them. Regards

[MS SQL Server] DBCC Table Check Long Running/Locking Issues

[MS SQL Server] DBCC Table Check Long Running/Locking Issues


DBCC Table Check Long Running/Locking Issues

Posted: 05 Mar 2013 06:46 AM PST

I have two 'identical' systems, both running SQL 2008 Enterprise with SP2 and Windows 2008 64bit. The DB's are around 800GB with 31,000 tables. When DBCC CHECKDB gets to the TABLE CHECK stage, on one it takes out a Sch-S lock on the table it is doing then clears the lock and moves on to the next table.When it runs that on the other it also takes out a Sch-S lock but doesn't release the previous one before it takes out the next one so the number of locks grows and grows as the DBCC progresses. The DBCC also runs for at least four times longer than normal when this behaviour happens. The estimated_completion_time in sys.dm_exec_requests seems to be correct to start with but extends as the job runs longer and longer. A reboot seems to fix the issue and it has happened 4 times in 12 months.The job isn't explicitly set to use TABLOCK and there are no messages in the errorlog. None of the reasons listed in the help page for DBCC regarding reasons why a snapshot can't be made seem applicable but do I assume it isn't using one??Any thoughts on what could cause this or what to look for next time it happens?

select permission on view

Posted: 06 Mar 2013 04:06 AM PST

I understand one reason to use view is for security.So we have a view and granted a user select permission to that view.But we got a denied message when select the view?The SELECT permission was denied on the object 'table1', database 'mydb', schema 'dbo'.It is denied because it doesn't have select for underlying table. My understand is we don't need underlying table permisson.Why it asks underlying table permission?One thing i notice though the view is different schema than the underlying table, does it make a difference?Thanks

2nd node on Cluster turned off by infrastructure

Posted: 06 Mar 2013 04:23 AM PST

I inherited a virtual Sql2008 (sp1) active/active Cluster for our SharePoint installation.Just determined the 2nd node in the Cluster has been turned off by infrastructure for awhile, business-as-usual.There are multiple articles available for how to remove the 2nd node (restart, setup.exe, maintenance,...)Is the 2nd node uninstall needed or do I now have a psuedo single node cluster?OR if I lose the first node will the Cluster be FUBAR?thanksEDIT: Just realized I placed the Topic in the wrong folder, should have been High - Availability

Database getting into recovery mode

Posted: 06 Mar 2013 03:43 AM PST

Database getting into recovery mode is every morning.

How notificate create database event

Posted: 02 Mar 2011 12:32 AM PST

Hi,I need to detect when a new database is created in my SQL Server and send a mail notification to all dba-s.My idea is to do that with notification services: first i capture the create database event, second i enquee message in the queue and finally i process this queue sending notification mails to all dba-s.Someone could tell me if it is possible? How I can read the messages from a queue to send notifications by mail? How i can see the queue content?Many thanks in advance.

sql connections

Posted: 06 Mar 2013 01:09 AM PST

I want to know whaich connections are using which driver / api to connect to my server.For instance I'm told one application is using ODBC which I am sure it is not.But how do you see ODBC, ADODB, OLEDB, ... from the server's prespective?

Question about DBA authority versus responsibility

Posted: 06 Mar 2013 12:10 AM PST

Hi,I'm looking for some advice for how I can assert myself in this situation without alienating my colleagues or causing trouble.I recently was asked to help fix a problem with an application, at which time I discovered that the application in question is running a SQL Server database that I wasn't aware of. Because it hadn't been set up with the basic log management stuff, the log grew to fill up almost the whole disk, causing the problem. I guess the first issue is that my organization has a separation of duties such that I am not notified about applications that run SQL Server databases. But beyond that, after I asked to be made sysadmin on the server so I can maintain it, I was told that this can be done but it doesn't fall under the databases that I need to maintain. Given that I was called in to fix the problem, of course, I think I am already maintaining it.The problem is, at the moment, that group installs and sets up SQL Server and then hands it over to me for applications that fall under my group. So I can't claim that I install and administer everything. However, I would feel better knowing that I am admin on systems that are running SQL Server, because I am the DBA and should anything happen with those servers, ultimate responsibility would lie with me anyway.I realize I don't have a specific question (maybe there is none), but I'm wondering if anyone out there has guidance for how I should proceed, or what I need to find out in order to proceed.Thanks for any help.- webrunner

Retrieving the T-SQL command syntax for a full and differential backup within a maintenance plan

Posted: 05 Mar 2013 11:28 PM PST

Hello --I have created several maintenance plans for backing up the databases on our server which include Full, Differential, and Transaction Log backups. When I created the plans, I made sure to have a text file generated for the transaction log backup which includes the T-SQL command syntax. However, I forgot to do the same for the Full and Differential backups.I would like to get the command syntax being used for the aforementioned backups, and I wanted to know how would I go about doing that?Thanks.

Lazy Writer

Posted: 05 Mar 2013 04:40 PM PST

Hi AllI want to begin by stating that I have read the corresponding chapters in the SQL 2008 Internals (Kalen Delaney) book and have consulted with other resources as well.I just want to confirm my understanding of the lazy writer process.The lazy writer process looks after both the data cache as well as the plan cache, using different algorithms for each cache.Is this correct?Thanks

System-health extended-event session does not capture latest deadlocks

Posted: 20 Dec 2012 08:04 PM PST

While running the following query to capture the latest deadlocks recorded in the default system-health extended-event session, I noticed that the latest deadlock captured was 3 days ago. However, in the SQL ERRORLOG I see that several deadlocks have occurred as recently as today.Has anyone else noticed this issue?[code="sql"]--http://www.quest.com/whitepaper/how-to-use-sql-servers-extended-events-and-notifications816315.aspx;WITH SystemHealthAS ( SELECT CAST ( target_data AS xml ) AS SessionXML FROM sys.dm_xe_session_targets st INNER JOIN sys.dm_xe_sessions s ON s.[address] = st.event_session_address WHERE name = 'system_health')SELECT Deadlock.value ( '@timestamp', 'datetime' ) AS DeadlockDateTime, CAST ( Deadlock.value ( '(data/value)[1]', 'Nvarchar(max)' ) AS XML ) AS DeadlockGraphFROM SystemHealth sCROSS APPLY SessionXML.nodes ( '//RingBufferTarget/event' ) AS t (Deadlock)WHERE Deadlock.value ( '@name', 'nvarchar(128)' ) = N'xml_deadlock_report'ORDER BY Deadlock.value ( '@timestamp', 'datetime' );[/code]

[Articles] Two Plugs Away

[Articles] Two Plugs Away


Two Plugs Away

Posted: 05 Mar 2013 11:00 PM PST

The culture and practices at Valve are interesting to Steve Jones, but the desks really caught his eye.

[SQL 2012] SQL Server Always On

[SQL 2012] SQL Server Always On


SQL Server Always On

Posted: 05 Mar 2013 08:53 PM PST

Hi,I have setup a clustered environment for my SQL Server database and configured Always On replication with no issues, everything seems to be working perfectly, however I have one problem that I'm hoping someone has the answer to?!I have configured Read Only Intent on my secondary replica and setup a dummy report in SSRS that simply gets the @@SERVERNAME property. I have configured the applicaton intent = read only within my connection string and when I run the report it works perfectly, returning the secondary server name as my result set.What I want to know is there a way that I can do this within a SP so that when it is executed it automatically offloads the query to the secondary replica?? I've been scouring the internet for awhile trying to find an answer to this but so far I'm coming up blank!!!!!!Any help is appreciated.Thanks

always on availability group performance

Posted: 05 Mar 2013 05:16 AM PST

I'm looking for a way (DMV query possibly) to see how far the secondary replica has fallen behind under heavy database load (inserts, updates, deletes) on the primary. In other words, is there a way to see how many transactions the secondary needs to apply so it is caught up and in sync with the primary? I would like to do some performance testing in our lab.Also, is there an easy way to see the performance overhead cost of sync compared to async?

Using 'dbghelp.dll' version '4.0.5'

Posted: 04 Feb 2013 11:32 AM PST

Hello,This isn't specific to SQL 2012 after doing a bit of Googling, but it's writing to my Sql Server log roughly once every 5 seconds so pretty annoying.We've just installed sharepoint portal on it. Any ideas how I can fix it please?thanks

Enabling Always On Option in sql server 2012

Posted: 05 Mar 2013 03:57 AM PST

Hi , I hope to enable this Always On Availability group option the server must be in failover clustering. In our environment we have one sql server 2012 enterprise edition and two sql server 2008r2 standard edition. Is it possible to configure fail over between these nodes . Any option to enable Always On option in sql server 2012 . Kindly share your views. Need to make use of this option in sql server 2012 .

[T-SQL] Add login, user, roles in mult db's dynamically

[T-SQL] Add login, user, roles in mult db's dynamically


Add login, user, roles in mult db's dynamically

Posted: 05 Mar 2013 11:43 PM PST

I am attempting to create T-SQL that I can re-use on different db's, users, domains, roles, etc…The trouble I'm having is when trying to change database names dynamically. I need the ability to hit multiple db's in one shot. My goal for starters is to only change the username parameter for each user/executio and execute the rest.I have attached the code. Any suggestions would be helpful - there must be a better way.This is what's failing after adding the +(@DB) variable:set @USER = + QUOTENAME(@DB) + 'CREATE USER ' + QUOTENAME(@DN + @UN) + ' FOR LOGIN ' + quotename(@DN + @UN) + ' WITH DEFAULT_SCHEMA=[' + @DN + @UN + ']' --db1

To find perfect expense?

Posted: 05 Mar 2013 01:18 PM PST

Hai friends, create table user( user_id varchar(100), name varchar(100), designation_id varchar(100), grade_id varchar(100))insert into user values('0012','abc',13,8)insert into user values('0010','bc',5,3)insert into user values('0011','bjc',2,3)insert into user values('0013','bct',6,3)insert into user values('0016','bci',59,35)insert into user values('0019','bcp',9,11) create table designation(desigantaion_id varchar(100),name varchar(100),grade_id varchar(100))insert into designation values('13','progrmmer',8)insert into designation values('5','GM','3')insert into designation values('2','regional manager','3')insert into designation values('6',' accounts manager','3')insert into designation values('59','worker','35')insert into designation values('9','trainee','11')create table sal(effective_date date, sala varchar(100), designation_id varchar(100)grade varchar(100))insert into sal values('2010-01-01','5000','13','b2')insert into sal values('2010-01-01','10000','5','a1')insert into sal values('2010-01-01','10000','2','a1')insert into sal values('2010-01-01','10000','6','a1')insert into sal values('2010-01-01','2000','59','e')insert into sal values('2010-01-01','3000','9','c')insert into sal values('2011-01-01','5500','13','b2')insert into sal values('2011-01-01','11000','5','a1')insert into sal values('2011-01-01','11000','2','a1')insert into sal values('2011-01-01','11000','6','a1')insert into sal values('2012-03-01','2500','59','e')insert into sal values('2012-02-01','3600','9','c')insert into sal values('2012-01-01','15000','6','a1')now i wanna make a join all the table,if i ' m pass the effective_date depends on the salry ll display all the employes.... such designations are missed on the '2012-01-01' in that... if i m pass the all effective _dates the outputs of sal shows '2010' and '2012','2011' also that each employess sal display three times i waana display the occurate sal of all employees depends on effective_dates.

ERD from existing database

Posted: 05 Mar 2013 09:40 AM PST

Hello,I need little help. I have an existing database and i need to have an ERD of this DB. Is there any tool which i can use (free tool) to draw ERD from this existing database?Please suggest,Thanks

How to-Combine 3 Storedprocedures O/P to get one output report without UNION clause

Posted: 05 Mar 2013 10:25 AM PST

Hi Friends,I have very complex functionality-I have developed 3 Stored Procedures- 1) Jobposting,2) WorkOrder and 3) Workernow the final step I want to do is-Combine the 3 Stored Procedures and get one single output the problem with UNION clause is that each of the 3 STored procedures have 2 sections of code - the 1st section has fields in different order than the 2nd second section for each stored procedure, and there are 300 fields so I wanted to know without the manual effort maintaing the same fields order in both sections of the code for each pass, instead is there anyother way this can be done using TEMP table in the start if yes , would be much obliged if I could get a sample code to get my above functionality accomplished please.ThanksDhananjay

substring issue

Posted: 05 Mar 2013 06:55 AM PST

Not sure what I am missing here possible brain freeze declare @loginname varchar(35)set @loginname = '<rxno>001c</rxno>\test1'select SUBSTRING(@loginname,CHARINDEX('<rxno>',@loginname)+1,CHARINDEX('</rxno>',@loginname)-CHARINDEX('rxno>',@loginname)-1) I want to return only 001c but I am getting rxno>001

Last business day of the month; Partial holiday calendar and tally table

Posted: 05 Mar 2013 12:30 AM PST

Hi Folks,I am trying to perform some if/else logic on the last business day of the month. I have a third- party provided partial holiday calendar, just the holidays.When I hard code the date, SET @StartDate = '2013-03-28', I am not getting my expected result Any suggestions? --Create the tally table if you don't have one-Courtesy Jeff Moden--===== Create and populate the Tally table on the fly/* SELECT TOP 11000 --equates to more than 30 years of dates IDENTITY(INT,1,1) AS N INTO dbo.Tally FROM Master.dbo.SysColumns sc1, Master.dbo.SysColumns sc2--===== Add a Primary Key to maximize performance ALTER TABLE dbo.Tally ADD CONSTRAINT PK_Tally_N PRIMARY KEY CLUSTERED (N) WITH FILLFACTOR = 100--===== Allow the general public to use it GRANT SELECT ON dbo.Tally TO PUBLIC*/CREATE TABLE #Holidays (HolidayDate datetime, IsHoliday char(1))INSERT INTO #Holidays (HolidayDate,IsHoliday) VALUES('2013-02-18 00:00:00.000', 'Y')INSERT INTO #Holidays (HolidayDate,IsHoliday) VALUES('2013-03-29 00:00:00.000', 'Y');DECLARE @StartDate DATEDECLARE @LastBusinessDayMonth DATESET @StartDate = GETDATE()--@LastBusinessDayMonth seems to be set properly hereSET @StartDate = '2013-03-28'--Doesn't work hereSET @LastBusinessDayMonth = ( SELECT TOP 1 MAX((DATEADD(dd, DATEDIFF(dd, 0, @StartDate), 0) + n)) FROM TALLY T LEFT JOIN #Holidays H ON H.HolidayDate = (DATEADD(dd, DATEDIFF(dd, 0, @StartDate), 0) + n) WHERE DATEPART ( mm , @StartDate ) = DATEPART ( mm , (DATEADD(dd, DATEDIFF(dd, 0, @StartDate), 0) + n) ) AND --Days in the current month DATEPART ( yy , @StartDate ) = DATEPART ( yy , (DATEADD(dd, DATEDIFF(dd, 0, @StartDate), 0) + n) ) AND --Days in the current year HolidayDate IS NULL AND --Exclude holidays DATEPART(WEEKDAY, (DATEADD(dd, DATEDIFF(dd, 0, @StartDate), 0) + n)) NOT IN (7,1)--Exclude weekends)PRINT @StartDatePRINT @LastBusinessDayMonthIF @LastBusinessDayMonth = @StartDateBEGINPRINT 'LastBusinessDay'ENDELSEBEGIN PRINT 'NotLastBusinessDay'ENDDROP TABLE #Holidays

[SQL Server 2008 issues] Attempt to fetch logical page (1:440) in database 2 failed. It belongs to allocation unit 422212869292032 not to 6269010747738816512.

[SQL Server 2008 issues] Attempt to fetch logical page (1:440) in database 2 failed. It belongs to allocation unit 422212869292032 not to 6269010747738816512.


Attempt to fetch logical page (1:440) in database 2 failed. It belongs to allocation unit 422212869292032 not to 6269010747738816512.

Posted: 05 Mar 2013 04:23 PM PST

hi all,One of my sp is giving the following error some times not every time:[b]Attempt to fetch logical page (1:440) in database 2 failed. It belongs to allocation unit 422212869292032 not to 6269010747738816512.[/b]can any one help on this.

Concatenate with a smallint variable

Posted: 05 Mar 2013 04:18 PM PST

Hi All,I could not format a column in the below,[u][i][b]declare @table table (mMonth smallint);insert into @table values (1),(9),(11),(12);select mMonth, LEN(mMonth) Length, case LEN(mMonth) when 1 then ('0'+CAST(mMonth AS VARCHAR(6))) else mMonth end formattedMMonthfrom @table[/b][/i][/u][i][b]case LEN(mMonth) when 1 then ('0'+CAST(mMonth AS VARCHAR(6))) else mMonth end formattedMMonth[/b][/i]keyword could not give the correct result.

SQL Server for Content Censorship

Posted: 05 Mar 2013 06:08 PM PST

Hi Champs,We have little strange requirement in a case of SharePoint where backend is SQL. Users in social features of SharePoint shout not be able use offensive words in comments, newsfeeds, conversations, reply etc, The system must not allow "offence words". Somehow it is not possible SharePoint automatically. We can do it only manually through content approval process. But that approach is not practical approach for the larger environment. What i was thinking if something can be done from the SQL Side as SharePoint stores Data in SQL. I was thinking something at runtime detection of Offensive words against a Master Table (Offensive word Dictionary) or While user post (Saved) also fine so SQL can compare and if found offensive Data it should tgriger alert for Admin. Please champs let me know if this approach is possible some how. Thanks.Regards,Inder.

Formatting issue in SQL

Posted: 04 Mar 2013 10:43 PM PST

Hello all, I have seen some strange things in my SQL Server 2008 enterprise edition. whenever I do sp_helptext for any procedure, some of the random linescome as two lines and this risks the code break. For example, if I have a code like this:create procedure Temp_Procedure@p1 varchar(20)asbeginselect * from dbo.Table1where Col1 = @p1and Col2 = 'Temporary'endIt shows as:create procedure Temp_Procedure@p1 varchar(20)asbeginselect * from dbo.Table1where Col1 = @p1and Col2 = 'Temporary'endIt looks simpler in this example but where the codes are of thousand lines, it becomes headache to format it again and again. I don't know if there is any environment variable setting or something. I have checked many a options but nothing worked.

Auto Update Statistics Asynchronously option

Posted: 05 Mar 2013 05:48 PM PST

Hi Does the option "Auto Update Statistics Asynchronously" work for update ,delete and insert statement or it is just used for select?I mean if I enable this option ,after update ,delete and insert would the statistics be updated?Also I have a nightly job that update statistics with full scan.

Execution Plan - Key Lookup

Posted: 05 Mar 2013 09:56 AM PST

I run the following query on the AdventureWorks database.SELECT ContactID,LastName,PhoneFROM Person.ContactWHERE EmailAddress LIKE 'sab%'In the execution plan, why is the "Key Lookup" operator appearing below the "Index Seek" operator and not after it.

Mirrored DB log file growth is High

Posted: 05 Mar 2013 03:45 PM PST

Hi all,I have mirroring setup in SQL 2008r2 server, Everything working fine.But MirroredDB LDF file growth is very high. How restrict the LDF file growth.With,Bharath.

SSIS not producing information from my COMPUTE BY clause when exporting to Excel

Posted: 05 Mar 2013 12:50 PM PST

When I run a script that uses COMPUTE BY in SSMS I get the desired results. When I try and create an SSIS package to export out to Excel, it completely ignores the COMPUTE BY clause. I need to do a subtotal by a certain group but I don't need to sum any of the columns.I've been reading about GROUP BY (ROLLUP) but I can't get that to work. It wants me to add every single column name into the GROUP BY clause which of course ruins how I want the data to look when it's exported out to Excel.Here's a sample of how I'd like the data to look like once it gets to Excel...[img]http://oi50.tinypic.com/2a9pgrn.jpg[/img]This is where I'd want a subtotal on the post_amt on every change in admit_svc_code. Like I said this works just fine if I use COMPUTE BY within SSMS but that line is ignored when I try and export it out to Excel. I know how to make this work if I export the raw data into Excel but I'd like the data to already look like that from the SSIS export.

Transactions

Posted: 05 Mar 2013 01:56 PM PST

Is it possible to update 2 Db with 2 different sqlConnections under same Transaction ?Thanks.

Disable AUTO_CREATE_STATISTICS and AUTO_CREATE_STATISTICS for all databases

Posted: 05 Mar 2013 02:18 PM PST

How to disable AUTO_CREATE_STATISTICS and AUTO_CREATE_STATISTICS for all databases in single step?

xml query datetime datatype problem while inserting to xml

Posted: 01 Mar 2013 06:57 PM PST

I have a query likeUPDATE aSET oldRemarks1.modify('insert <Value_Py>{sql:column("b.collection_date")}</Value_Py> after (/Root/Row[3]/Item)[1]') from b where a.[Date]='31-May-2004' and a.sl_no=b.regkey_slnoHere collection_date is of datetime datatype.So while it is inserted to xml it will be like 2012-03-05T00:00:00.000 in the xml tag.But i want to insert it as just "2012-03-05" in the xml tag. So how can i use cast or any other method here so that it will insert properly in xml.

Publish SSRS 2008 in LAN

Posted: 27 Feb 2013 03:51 PM PST

How to publish SSRS for internal alone.I have a project which needs to be circulated only to my team members using my hostname.What are the steps to deploy them.now i am able to do with http://localhost/Reportshttp://myhost-name/Reportswhere as if i see in another machine [b]http://myhost-name/Reports[/b] i am unable to get the details.Thanks

RANK function used over a partion - unexpected result

Posted: 05 Mar 2013 11:33 AM PST

Hi,I have the following table / data:[code="other"]id Title Director===================================1 movi dir1 2 mo dir2 3 movie333 dir333 4 movie dir4 5 movie dir4 6 movie dir4 [/code]If I run the statement:[code="sql"] select id, title, director, RANK() over (partition by title order by (select 0)) as RNKfrom Movies; [/code]I get the following result:[code="other"]id Title Director RNK===========================================2 mo dir2 11 movi dir1 14 movie dir4 15 movie dir4 16 movie dir4 13 movie333 dir333 1[/code]I would expect the RNK value for id =4,5,6 would be 1,2,3Why are the values for id = 4,5,6 identical?Thank you for help.

Issue with a Connection to a Named Instance in Home Lab

Posted: 05 Mar 2013 10:15 AM PST

I installed a single named instance of SQL Server in my lab, and I am having trouble connecting from a remote machine, although local connections to the instance work fine. The server hosting SQL Server is a brand new VMware Workstation virtual machine that does not have any other SQL Server versions or instances installed.On the database server, I used SQL Server Configuration Manager to change the TCP port to static 1433.On the database server, I opened the firewall with the following commands:[code="plain"]netsh advfirewall firewall add rule name = SQLPort dir = in protocol = tcp action = allow localport = 1433 remoteip = localsubnet profile = DOMAINnetsh advfirewall firewall add rule name = SQLPort_1434 dir = out protocol = UDP action = allow localport = 1434[/code]PortQry.exe shows 1433 open when I run it from the remote machine that I am using to connect to SQL Server.Scenario 1: Surprisingly, this command (which does not specify the instance name) works on the remote machine:[code="plain"]sqlcmd.exe -S sql_netbios_name -U sa -P password -Q "select getdate()"[/code]Scenario 2: This command (which specifies the instance name) gets an error error (which I am attempting to fix with this web posting) on the remote machine:[code="plain"]sqlcmd.exe -S sql_netbios_name\instance_name -U sa -P password -Q "select getdate()"HResult 0xFFFFFFFF, Level 16, State 1SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : Login timeout expired.[/code]Scenario 3: But this command (which specifies the instance name *AND* the port number, with the connection string encapsulated in double quotes) works on the remote machine:[code="plain"]sqlcmd.exe -S "sql_netbios_name\instance_name,1433" -U sa -P password -Q "select getdate()"[/code]Any ideas why Scenario 2 fails? This has to be simple. I just don't see it.

If I compress a primary key, am I compressing the whole table --&gt; P-key with DATA_COMPRESSION

Posted: 05 Mar 2013 06:56 AM PST

Can someone explain how data compression works at the index level? If I compress a primary key, am I compressing the whole table [since the data pages are leaf pages]?

Joining to Multiple rows which should really be one row

Posted: 05 Mar 2013 08:32 AM PST

Hi, looking for some help or advice if possible, been searching this all night with no luck, im probably not using the correct search terms. I am loading Mainframe data into SQL Server 2008. There is a master record Table which I need to join to a notes table. The Master Record might have name, address, job title etc, and the Notes Table contains a note. The thing that makes this a bit unusual is as this has come off the mainframe due to file space considerations the notes field was split over multiple rows.So you having something like thisMaster TableID, Name, Address, Job Desc1, Bob", "New York","Sports Reporter"2,"Chris","Washington","Doctor"Notes TableID, EmpID,Note1,2,"Chris has been"2,2,"a doctor in the"3,2,"USA for 5 years."I want a select statment to output rows for reporting purposes (using SSRS) which would say something like this..2,"Chris","Washington","Doctor","Chris has been a doctor in the USA for 5 years"Can anyone point me in the right direction? I hope I have explained it clearly.Thanks

convert 2000 db to 2008 r2 db

Posted: 05 Mar 2013 03:06 AM PST

Upgrade to 2008r2 from 2000. Backup the 2000 db and restore to 2008 r2. Create all application users and add all the role and right same as 2000.When I point the appl to new 2008 r2 db, it said my application user does not have 'execute' right to one stored procedure.But when I point back to 2000 db, everything is OK. The application is up as usual.I find out that my appl user does not have 'execute' right for that stored procedure too on 2000.It seems I am missing something. Anything is default in 2000 but I need to grant manually??Or anything about right or role I do not pay attention when upgrading from 2000 to 2008 r2.Hope anyone can give me some advicesThanks a lot

Displaying Data From 3 SQL Tables On A Form

Posted: 05 Mar 2013 03:23 AM PST

I have a program of my own, for my own use, written in Excel VBA that I want to rewrite in VB2010 Express using SQLCE.It currently displays a Form as per the picture attached.What is the best way of replicating something similar ? I know I can create individual Buttons & TextBoxes for each Row, but I am wondering if there is a better way. I tried using DataGridView, but [b](a)[/b] it's pretty ugly & [b](b)[/b] it doesn't let me use more than one Table !!!I don't mind using a load individual Buttons & TextBoxes, but thought I would ask people who might know better, before doing so ;-) !!!

create procedure which contains special caracters from .sql file with sql powershell

Posted: 05 Mar 2013 07:22 AM PST

Hello,I have a .sql file which is actualy the body of a stored procedure. The procedure containts characters like [b]'é, à, è...'[/b]. when i run the command:[b]invoke-sqlcmd -server "servername" -database "databasename" -inputfile "filename.sql" [/b] against MS SQLServer, the procedure is succesfully created, but in place of characters listed above I have a [b]'?'[/b].As work around I found somthing like:[b]PS SQLSERVER:\>$server="servername"PS SQLSERVER:\>$database="databasename"PS SQLSERVER:\> $query=get-content -path "path_to_file..."PS SQLSERVER:\> $connection=new-object System.Data.SqlClient.SQLConnectionPS SQLSERVER:\> $connection.ConnectionString="Server={0};Database={1};IntegratedSecurity=True" -f $server,$databasePS SQLSERVER:\> $command = new-object System.Data.SQLClient.SQLCommand($query, $connection)PS SQLSERVER:\> $connection.Open()PS SQLSERVER:\> $command.ExecuteScalar()PS SQLSERVER:\>$connection.Close()[/b]Now the troublesome characters are all in place, but the generated procedure is a loooooooong line.Is there a way to make this right with SQLPS? Is there a option(like sqlcmd -u)for unicode files?Thank you!

Data Tier Application - Copies and Deletes existing Security??

Posted: 05 Mar 2013 07:10 AM PST

I know there is little written about the data tier architecture, and I have read the white papers, etc.. but it seems strange in an application designed for moving sql projects from devt to production that there is no way of stopping the dropping of the existing security that is on the Prod environment. Let me expand...Steps:1/ Have a working devt, etc envs configured with a devt, test... configurations (data tier registrered)2/ Have a working Prod env configured with a prod configuration (data tier registrered)3/ Have a release candidate on the devt machine4/ Export the data tier at the devt rc (which contains all the devt security; You can exclude the security from the created package)5/ Upgrade the prod env....Wait! Even though I removed the devt security, the comparison of the schemas has told slq to drop all the current prod users/logins/schemas that were not on the devt env (which is basically the prod security)..:w00t:Doh!How can you remove the comparison of the security - Add to the built dacpac the production security(lame and has further complications re SQL logins needing to be re-enabled and if on differing domains; What about windows logins)?? How were they thinking this would work in a production deploy? If you have an idea, or can see I am missing something please let me know.

fetch tables most often queried

Posted: 26 Feb 2013 12:24 PM PST

Is there a way to determine which tables of a database are being queried most often, sorted in descending order?

What is the purpose of "Register as Data-tier Application" ?

Posted: 26 Sep 2010 10:18 PM PDT

As I can use "Extract Data-tier Application" to generate a dacpac file, what is the purpose of "Register as Data-tier Application" ?Do you the reason of it ?

T-Sql Logical Query

Posted: 05 Mar 2013 04:55 AM PST

Hi all - I was presented with a request today which I'm completely stumped on.Here it is; Given an employees table with the columns ID, FirstName, LastName, HireDate, and TerminationDate how would you calculate the longest period in days that the company has gone without hiring or firing anyone.Any help would be greatly appreciated. Thanks, RJ

performance

Posted: 05 Mar 2013 03:04 AM PST

as part of environment refresh i am restoring prod back up to a test server.both prod and test are in same domainand i am using Quest lite speed to restore (from target server I am selecting prod backup file through network).So my question is - is there any performance issues on production arise? network slowness? or any other issues?Thanks.

Alter User Defined Data Type

Posted: 05 Mar 2013 04:23 AM PST

I'm trying to alter a column in a table that corresponds to UDDT, this column has a primary key and it reference to foriegn key in other tables. What should be the approach to accompolish this task. So many objects has dependencies on this UDDT

Execution completed with errors

Posted: 05 Mar 2013 02:19 AM PST

We have defined a cursor and a transaction which empowers to process data record by record. The desired behavior is If there is a failure in an iteration then it should rollback transaction, log error in a custom table and proceed for next record in the queue, finally the stored procedure should indicate execution as successful.As per mentioned logic, in SQL Server 2008 it performs same as of above explained requirements and completes its execution whereas in SQL Server 2000 it also completes execution but prompts error message at the end of stored procedure execution if there was an error during execution of an iteration. Our external application fires a stored procedure in SQL Server 2000 which contain similar logic and gets fail if there was an error in an iteration. We want to achieve same behavior in SQL Server 2000 as of SQL Server 2008's behavior.[u][b]SQL Server 2000 T-SQL Code:[/b][/u]DECLARE @Flag AS INTDECLARE @ErrorCode AS INTDECLARE CSR_TEST CURSORFOR SELECT 1 AS Flag UNION SELECT 2 AS Flag OPEN CSR_TEST FETCH NEXT FROM CSR_TEST INTO @FlagWHILE @@FETCH_STATUS = 0 BEGIN BEGIN TRANSACTION IF @Flag = 1 BEGIN SELECT 1 / 0 SELECT @ErrorCode = @@Error IF @ErrorCode <> 0 GOTO LogError END IF @Flag = 2 BEGIN SELECT 1 / 1 SELECT @ErrorCode = @@Error IF @ErrorCode <> 0 GOTO LogError END COMMIT TRANSACTION PRINT 'COMMIT TRANSACTION' GOTO ProcEnd LogError: ROLLBACK TRANSACTION PRINT 'ROLLBACK TRANSACTIOM' --Error Logging in Custom Table ProcEnd: FETCH NEXT FROM CSR_TEST INTO @Flag END CLOSE CSR_TESTDEALLOCATE CSR_TEST[u][b]SQL Server 2008 T-SQL Code:[/b][/u]DECLARE @Flag AS INTDECLARE @ErrorCode AS INTDECLARE CSR_TEST CURSORFOR SELECT 1 AS Flag UNION SELECT 2 AS Flag OPEN CSR_TEST FETCH NEXT FROM CSR_TEST INTO @FlagWHILE @@FETCH_STATUS = 0 BEGIN BEGIN TRY BEGIN TRANSACTION IF @Flag = 1 BEGIN SELECT 1 / 0 SELECT @ErrorCode = @@Error IF @ErrorCode <> 0 RAISERROR (8134,0,0) END IF @Flag = 2 BEGIN SELECT 1 / 1 SELECT @ErrorCode = @@Error IF @ErrorCode <> 0 RAISERROR (8134,0,0) END COMMIT TRANSACTION PRINT 'COMMIT TRANSACTION' END TRY BEGIN CATCH ROLLBACK TRANSACTION PRINT 'ROLLBACK TRANSACTIOM' --Error Logging in Custom Table END CATCH FETCH NEXT FROM CSR_TEST INTO @Flag END CLOSE CSR_TESTDEALLOCATE CSR_TEST

Copying from SQLSMS grid, pasting in Excel, the word "NULL" is pasted!

Posted: 05 Mar 2013 01:58 AM PST

When I copy/paste grid results from SQL Server Management Studio --> an Excel file, the WORD "NULL", the actual letters "N" "U" "L" and "L" are pasted into the cell for all NULL values.Dear geniuses at Microsoft: A NULL value does not equal the string "NULL" !!!!Those are two completely different things. Making users to a find/replace post-paste is ridiculous. Making us encapsulate every single field separately in our select with an ISNULL(Field,'') is ridiculous. What if a user has a SELECT * which contains hundreds of columns that they want to copy/paste into Excel?By now, I should not be surprised when a Microsoft product does something silly like this, but for the life of me, I cannot [i]believe[/i] this is the native behavior of SQL Server Management Studio.Please, somebody, tell me there is an option or setting in SQLSMS that I am missing to prevent this very silly behavior.

Transactional Replication - Report last synchronisation date

Posted: 04 Mar 2013 08:38 PM PST

Hi all, apologies if this has been asked before, I tried searching and came up with nothing.I'm using Transactional Replication to Push a publication out to several other machines. These machines are used for reporting off, and there's a requirement to show on these reports how old the data is. So the idea is to show something like "Last updated 05-Mar-2013 11:29:00".My question is whether it's possible to query this information from the subscriber server/database alone? I'm aware that there's various means of doing it from the publisher, but these machines are to be used for disaster recovery reports and as such we can't rely on being able to access the publisher server.I've considered:a) Putting triggers on the tables in the subscriber DB to update a "last updated" table on each operation.b) Customising the Insert/Delete/Update SPs for each table to update a "last updated" table.But I was hoping to be able to avoid either of those, simply to keep the complexity of the replication solution to a minimum. No amount of googling has come up with anything, but I could just be using the wrong search terms!Does anyone have any clever ideas for how to get this information?Thanks in advance

Row level locking

Posted: 05 Mar 2013 01:32 AM PST

How to find row level locking is enabled or disabled for the tables?Thanks

Virtualization - yet again ...

Posted: 05 Mar 2013 01:56 AM PST

I spent some time searching this forum and the interwebs and haven't found a lot of definitive insight/agreement on virtualization and best practices. So here we go with another VM thread.I'm seeing issues with virtualiztion that seem obvious on the surface, but maybe I'm naive and too old school.DB 101 says, in general, separate MDF and LDF files to separate disk drives. Does this still apply in a virtual environment? I have to think yes. Which means I have to have the sys admins that host our environment make sure that log and data files are separate on the physical hardware not just in the virtual layer. They resist divulging such things.Similar issue with CPUs. A virtual server really doesn't know what it's running on. It could be sharing those 16 cores with 4 other instances and not even know it. So it seems reasonable that the actual CPUs should be explicitly allocated to specific SQL instances. though I suppose this might be more for high volume instances that are expected to have constant high CPU utilization.I recently ran into a technique for dealing with tembDB contention that recommended placing the tempDB files across several disk depending on the number of CPUs since each CPU could handle a tempDB thread separately during I/O. Which means knowing the real CPU resources available, not the virtual, and the real configuration of the disk arrays.Memory allocation was well figures in. A virtual instance can be assigned a max amount of memory that it may never actually get if the physical host has already doled it out. Rebooting an instance would also free up memory on the physical hardware and another virtual instance might grab that, no? Which would leave the rebooted instance starved for memory even if it is "assigned" a specific amount through the virtualization.So, in general, it seems to me that if you are virtualizing SQL servers, you have to drill down through the virtual layer and make sure the physical resources are properly allocated to the instances.Clustering gets interesting if the nodes on a cluster happen to share some physical resource. If that resource fails you have the pleasure of multiple nodes on your cluster dropping off.This makes me wonder if virtualization is even worth the effort in some cases. The idea behind server consolidation is to make sure your hardware is fully utilized. If a single instance of SQL A high availaibility, high volume system seems to less a candidate for virtualization than say a number of low volume instances for say departmental databases that seem to proliferate in many organizations.Sorry for the rambling. I just don't see a lot of definitive answers to some pretty serious issues when it comes to business continuity, performance, etc when it comes to virtualizing servers. Seems like it has become "the thing to do" and not enough thought is given to the needs of the entire database environment. The best practice should be to examine the information system, then decide if virtualization meets the need or not - not simply plop your junk on a virtual environment because some white paper says it will save you money.Thoughts?

Unexplained query plan differences between two near identical queries

Posted: 05 Mar 2013 01:25 AM PST

All:I have noticed some behavior that I can't explain with sql similar to the following. It is reproducible on multiple machines in our enterprise so isn't machine specific. Basically by moving the insert statement to put data into a temp table outside of dynamic sql vs. inside the dynamic sql, we are seeing completely different query plans and performance which seems ... strange.It seems that this is a scope issue but I'm curious if somebody has a more specific explanation of what we are seeing.My example:CREATE #table (myFoo varchar(10) )DECLARE @sql NVARCHAR(MAX) = ' INSERT INTO #table SELECT foo FROM bar'EXEC (@sql)Results in:SQL Server Execution Times: CPU time = 858 ms, elapsed time = 862 ms.VS:CREATE #table (myFoo varchar(10) )DECLARE @sql NVARCHAR(MAX) = ' SELECT foo FROM bar'INSERT INTO #tableEXEC (@sql)Results in: SQL Server Execution Times: CPU time = 47 ms, elapsed time = 51 ms. and a much better and different planCan somebody please explain what is happening?Thanks,

Query comes to a crawl until executed using the WITH RECOMPILE option

Posted: 05 Mar 2013 12:37 AM PST

we have a stored procedure that will run just fine for a couple of hours but then somewhere during that time its execution plan seems to get confused and executing it then comes to crawlwhen executing the stored procedure using the WITH RECOMPILE option we see that query begins executing at what we consider a normal amount of time again and will usually for a while, but eventually it slows down to a crawl againcurrently, a simple fix for us is to leave the WITH RECOMPILE option in the stored procedurehowever, we'd like to get a better understanding and come to an actual resolution if possible rather than this "workaround"any insight is greatly appreciated, thanks in advance!

Search This Blog