Quantcast
Channel: SQLServerCentral » SQL Server 2008 » SQL Server 2008 - General » Latest topics
Viewing all 16406 articles
Browse latest View live

How to see index coding

$
0
0
Hi Experts ,sp_helptext view_name sp_helptext Procedure_name but how can i see index code :sp_helptext index_name --> i got error from this code

Index usage

$
0
0
Hi,Is it possible to get last_user_seeks, scans, etc. for a specific partition aligned index? The following query only shows the seeks, scan for the whole index - I'd like it broken down by partition if possible.[code="sql"]SELECT prs.partition_number ,IDX.[name] AS [Index] ,fg.name AS 'FileGroupName' ,US.[user_seeks] ,US.[user_scans] ,US.[user_lookups] ,US.[user_updates] ,US.[last_user_seek] ,US.[last_user_scan] ,US.[last_user_lookup] ,US.[last_user_update]FROM [sys].[dm_db_index_usage_stats] USINNER JOIN [sys].[indexes] IDX ON IDX.[index_id] = US.[index_id] AND IDX.[object_id] = US.[object_id]INNER JOIN [sys].[dm_db_partition_stats] PRS ON PRS.[index_id] = US.[index_id] AND PRS.[object_id] = US.[object_id] INNER JOIN [sys].[databases] DB ON DB.[database_id] = US.database_idJOIN sys.partitions p ON idx.object_id=p.object_id AND idx.index_id=p.index_id AND prs.partition_number = p.partition_numberJOIN sys.partition_schemes schm ON idx.data_space_id = schm.data_space_idJOIN sys.partition_functions pf ON pf.function_id = schm.function_id LEFT JOIN sys.partition_range_values rv on rv.function_id = pf.function_id AND rv.boundary_id = p.partition_numberJOIN sys.allocation_units au ON au.container_id = p.hobt_id AND au.[type] = 1JOIN sys.filegroups fg ON fg.data_space_id = au.data_space_id WHERE db.name = 'xxxxx' AND OBJECT_NAME(IDX.[object_id]) = 'xxxx'ORDER BY PRS.partition_number ASC[/code]

Question on Transaction Replication

$
0
0
HiWe have 10 databases on a server and I have a requirement to centralize the data into 1 database in realtime. I was looking at transactional replication and it works well, however, the source tables don't have any information to indicate a source name. So all the data from multiple databases doesn't have the source information to make sense of the data. Adding additional column to the source tables will fix the issue, but we have 250+ tables in each database and an application sitting on it, so adding the new columns will be a hassle.Do you have any suggestions?Thanks

What is the system view for sys.syscolpars?

$
0
0
I am checking system base table at https://msdn.microsoft.com/en-us/library/ms179503.aspx and system internal views at https://technet.microsoft.com/en-us/library/ms189600(v=sql.105).aspxFor base table sys.syscolpars, is there a corresponding system view for it so that I can access its data without loginning in DAC mode?Thanks

Reindex DB on regular basis

$
0
0
Hi all!I have a database where app. 10.000 records are deleted/updated/inserted pr. day.I have understood from other sources, that i should reindex the db on a regular basis.Locally, where i backup/restores it up to many times pr. day, the speed has went down to a crawl.Where do i find some 'Hands on' info on 'How to', and pro et cons?The database is today a 2008R2, but wil get updated to 2012 or 2016 sooner or laterDB size: 26807,88 MBBest regardsEdvard Korsbæk

DBCC SHRINKFILE on data file - no errors, but no shrinking

$
0
0
We recently completed a project to move data to a new system. The old system's production database is still in use, but only to allow our users to enter time clock data.All old production data was removed from the system over the course of 4 months. We moved all data relevant to a specific location out of the production system into a historical database (with the same DB structure).So the production DB dropped in used space form over 400GB to 11 GB. Throughout the process (to make room for the growing historical database), I periodically shrank the production DB data file.However, towards the end of the project, I encountered a problem. I would run the DBCC SHRINKFILE command; it would complete successfully (no errors reported) - but the data file would be the same size.The data file is currently stuck at 128GB (11GB of which are in use, as I noted earlier).I have tried: - running DBCC SHRINKFILE with different target sizes, to remove as little as 1GB, and as much as 50GB. No change. - Changing the initial file size to something smaller (the changes won't take). - Changing the initial file size to something larger (forcing the DB file to grow slightly, which has helped in the past when I was getting errors when trying to perform a shrink); the file still won't shrink. - Tried again after a reboot; no change. - Tried restoring the latest backup of the database to another server, and shrinking there; no change.DBCC CHECKDB is regularly run on the database, and no problems have been reported.The server where this database resides will be decommed shortly. I'll need to move this to another server (at which point, it will also be just historical data). I'll like not to have to waste 100GB on the new server.REMINDER: I'm trying to shrink the [i]data[/i] file, no a transaction log file. And, in the past, I've been able to perform shrinks on this particular data file, with no problems. And, this is a situation where the DB will [b]never[/b] grow again, so shrinking it isn't a bad idea from that perspective.Any suggestions?

Error converting data type nvarchar to float

$
0
0
Hi Error converting data type nvarchar to float is returning Select Convert(mycolumn as float) from mytable;mycolumn is nvarchar(100)but my destination table is float , so i am converting to float, but getting error "[b]Error converting data type nvarchar to float[/b]"there are 10 million records in it, dont know which record is causing problem. how to sought it .Advance thanks!

Backup device '\\.\Tape0' failed to open. Operating system error 5(Access is denied.).

$
0
0
Hi everyone.Im running into an issue trying to configure my new LTO drive inside SQL.I've verified that the tape drive is functional using the HP tools, but all of the resources I can find list fixing this issue by granting the service account access when the target is a file not a tape drive.Where do i need to grant the service account access so it can use the physical device?Any help is greatly appreciated!Thanks,Josh

syscolpars.colid is inconsistent with system_internals_partition_columns.partition_column_id?

$
0
0
Hi,I get a SQL Server 2008 database called ‘BLANK’. And it contains several tables, one of them is ‘MyTable’. Its object ID is 480720765.I find a very strange problem in the table.When I login as DAC mode and using the following statements:USE BLANK;select * from sys.syscolpars where id = 480720765;I will get all the columns for ‘MyTable’, and their colid is from 1 to 21, as below:[img]https://social.msdn.microsoft.com/Forums/getfile/977856[/img]But when I use the following statements to find the partition id for the table:USE BLANK;select partition_id from sys.system_internals_partitions where (object_id = '480720765') AND (index_id <= 1);I will get the partition id as 72057594062897152.Then if I use the following statements to find the columns of the partition:USE BLANK;select * from sys.system_internals_partition_columns where partition_id = '72057594062897152';I will get all the columns for the partition, but the partition_column_id is from 0 to 20, instead of from 1 to 21.Below is the result:[img]https://social.msdn.microsoft.com/Forums/getfile/977858[/img]Originally I think syscolpars.colid should equal to system_internals_partition_columns.partition_column_id, since all other tables follow this way. But ‘MyTable’ is not. Why?Thanks

Separate List into Rows

$
0
0
Looking for a non-user function that will allow me to separate items within a field, only separated by a comma, into new rows.I'm not too familiar with SUBSTRING and CHARINDEX; however, the examples I found all seem to utilize these.Here's what I've attempted, but not seeing the required results.[code="sql"],SUBSTRING(TechnologyTeams, CHARINDEX(',', TechnologyTeams) , CHARINDEX(',', TechnologyTeams, 0) ) AS [TechTeam][/code]My field looks like this:Business Intelligence, Custom Applications - Roll (All apps except Loss Mit), Data Management, Web/MiddlewareQuery Results:, Custom Applications So I got one, and only one team, from the string but still missing the others. Also wouldn't need the leading comma in the current query results. Any suggestions?

Using Substring with ContainsTable

$
0
0
Hi there, I want to do FulltextSearch on only 500 characters of columns in a table to find employees and companies that use Natural Language processing (NLP)Employee table has Employee ID, COmpanyNames, Present jobdescription and Brief description of company and ManagerID(if exists).I want to do this[code="sql"]CONTAINSTABLE(dbo.Employee, (SUBSTRING(JobDescription,1,500),CompanyInfo),'ISABOUT("NLP" weight(.1))',LANGUAGE N'English',1000000) as fti[/code]But I get an error saying that "Incorrect syntax near '('."How can I do thisThanksMR

SQL Server Call/ SSIS to REST API Web Service (Workday) - (Not Weather API)

$
0
0
Hi All,I'm looking to call a web service (REST API/SOAP) doesn't matter through SSIS/Stored procedure. SSIS does have a web service call but it only accepts simple WSDL files and cannot read other methods. I tried this through stored procedure and get other errors. Still working to get my SOAP message right I guess.[code="xml"]http://www.vishalseth.com/post/2009/12/22/Call-a-webservice-from-TSQL-(Stored-Procedure)-using-MSXML.aspx[/code]ZaapSys does have a Powerpack utility and it works but it's paid. I can build the Integration from the workday side but then it's a 2 way step like dump a csv, run a listener and grab the file.Does anyone have a better approach ?Thanks,V

How to imbed an image into an email sent by dbmail

$
0
0
Hello all and thank you in advance for your time and expertise.I am sending out customer statements in email using dbmail on sql 2008. I'd like to put our corporate logo on top of the email, but I'm having difficulty doing it. I found an article on the web that showed me how to put html tags into documents (I'm not a programmer, in case you can't tell :-)) and I have this line in my sql statement:<img src="\\waccounting\images\logo.gif" width="400" height="100" border="0"/>When the email goes out, the image is blank on the email. Has anyone been able to put an image into their emails that get sent out by dbmail? If so, how?

Trying to rank the 0.000 data as well

$
0
0
I have a table of 33k rows and I have no issues ranking where there are values over 0.000, it is the values that are 0.000 that I have a problem with and not sure how to account for them:This is the code I am using:<code>/*ranking*/select compmcd.hedismeasure, compmcd.measureid, compmcd.competitor, compmcd.market, compmcd.prodabbrev, compmcd.hedisrate, (select count(*)+1 from anthemq.dbo.compmcd as t2 where t2.hedisrate > compmcd.hedisrate AND t2.measureid = compmcd.measureid and t2.market = compmcd.market and t2.prodabbrev = compmcd.prodabbrev) as rank into comprankfrom compmcd where hedisrate is not nullorder by compmcd.measureid desc , compmcd.market, compmcd.prodabbrev, compmcd.hedisrate desc;</code>When I run this I get this back what is in the attachment on the first set of rows but what I need is what is on the lower portion of rows.I know it is because the code is looking at the maximum values and because there are multiple entities that have 0.000 it gives them all the same rank because it does not know how to rank it. But I am not sure how to account for that other than to go through and do like 0.0001, 0.0002 for anyone that has a 0.0000 so I can get a correct rank

How to get Current Financial months.

$
0
0
Hi,i want to get current financial year months data, financial year starts from jul and ending jun.CREATE table #test(FinancialDate date)INSERT INTO #testVALUES ('2017-12-31'),('2017-11-30'),('2017-10-31'),('2017-09-30'),('2017-08-31'),('2017-07-31'),('2017-06-30'),('2017-05-31'),('2017-04-30'),('2017-03-31'),('2017-02-28'),('2017-01-31'),('2016-12-31'),('2016-11-30'),('2016-10-31'),('2016-09-30'),('2016-08-31'),('2016-07-31'),('2016-06-30'),('2016-05-31'),('2016-04-30'),('2016-03-31'),('2016-02-29'),('2016-01-31'),('2015-12-31'),('2015-11-30'),('2015-10-31'),('2015-09-30'),('2015-08-31'),('2015-07-31'),('2015-06-30'),('2015-05-31'),('2015-04-30'),('2015-03-31'),('2015-02-28'),('2015-01-31')Expected result:Jul 2016Aug 2016Sep 2016Oct 2016Nov 2016Dec 2016Thank you.

Emails worked within 3 working days

$
0
0
Hi guys,I had this task at work and I solved it, but I'd like to know if there is a better solution. I don't want "ready-made food", just a hint, a function I could use instead of my solution which works fine (as far as I know). In short, this is the task: calculate if the emails are worked/updated (wqi.Status_Updated_On) within 3 working days from the day they have been received (wqi.Created_On), then excluding the week-ends. Emails can be worked on Saturday and Sunday as well. I used the CASE and the DATEPART function. Monday and Tuesday are quite easy:[code="sql"]SLA = CASE WHEN DATEPART(dw, wqi.Created_On) = 2 -- 2 stands for Monday, the day the email has been received AND DATEPART(dw, wqi.Status_Updated_On) IN (2, 3, 4, 5) -- Updated on Monday or the 3 following days AND DATEPART(ww, wqi.Created_On) = DATEPART(ww, wqi.Status_Updated_On) -- CreatedDate and UpdatedDate are in the same week THEN 'Within SLA'[/code]The other days of the week are trickier, but I found this solution. This is Friday:[code="sql"]WHEN DATEPART(dw, wqi.Created_On) = 6 -- 6 stands for Friday, the day the email has been received AND ( ( DATEPART(dw, wqi.Status_Updated_On) IN (6, 7) -- Updated on Friday or Saturday AND DATEPART(ww, wqi.Created_On) = DATEPART(ww, wqi.Status_Updated_On) -- CreatedDate and UpdatedDate are in the same week ) OR ( DATEPART(dw, wqi.Status_Updated_On) IN (1, 2, 3, 4) -- Updated on Sunday, Monday, Tuesday, Wednesday AND DATEPART(ww, DATEADD(ww, 1, wqi.Created_On)) = DATEPART(ww, wqi.Status_Updated_On) -- The UpdatedDate falls in the next week ) ) THEN 'Within SLA' [/code]Any suggestions?

Summing up items in XML field

$
0
0
Hi Looking to sum "Monthly_x0020_Income_x0020_Amount" in the XML field below In this example there is only one , sometimes more than one...ThanksData>... <Income_x0020_Source_x0020_Amount> <ST2> <Monthly_x0020_Income_x0020_Amount>547</Monthly_x0020_Income_x0020_Amount> </ST2> </Income_x0020_Source_x0020_Amount> <non_x0020_cash_x0020_ST>

?? Flattening XML field

$
0
0
HiI am trying to flatten an XML field where each "source" would be listed no matter if there was an "amount" or not.So below is the xml data and how I would like it displayed. I tried using and index but since the XML display a source for each field it displays the wrong source for the amount XML Data:<Data> <Insurance>Yes</Insurance> <_x0031_._x0020_ealth>Yes</_x0031_._x0020_ealth> <Income_x0020_sources>Yes</Income_x0020_sources> <Non_x0020_Cash_x0020_Benefits>Yes</Non_x0020_Cash_x0020_Benefits> <Monthly_x0020_Income> <Monthly_x0020_Income_x0020_ST> [b] <Source>Earned Income</Source>[/b] </Monthly_x0020_Income_x0020_ST> <Monthly_x0020_Income_x0020_ST> [b]<Source>Unemployment Insurance</Source>[/b] </Monthly_x0020_Income_x0020_ST> <Monthly_x0020_Income_x0020_ST> [b] <Source>Supplemental Security Income</Source>[/b] </Monthly_x0020_Income_x0020_ST> <Monthly_x0020_Income_x0020_ST> <Source>Social Security Disability Income</Source> </Monthly_x0020_Income_x0020_ST> <Monthly_x0020_Income_x0020_ST> <Source>VA Service-Connected DIsability Compensation</Source> </Monthly_x0020_Income_x0020_ST> <Monthly_x0020_Income_x0020_ST> <Source>VA Non-Service Connected Disability Pension</Source> </Monthly_x0020_Income_x0020_ST> <Monthly_x0020_Income_x0020_ST> <Source>Private Disability Insurance</Source> </Monthly_x0020_Income_x0020_ST> <Monthly_x0020_Income_x0020_ST> <Source>Worker's Compensation</Source> </Monthly_x0020_Income_x0020_ST> <Monthly_x0020_Income_x0020_ST> <Source>Temporary Assistance for Needy Families (TANF)</Source> </Monthly_x0020_Income_x0020_ST> <Monthly_x0020_Income_x0020_ST> <Source>General Assistance (GA)</Source> <Amount>303</Amount> </Monthly_x0020_Income_x0020_ST> <Monthly_x0020_Income_x0020_ST> <Source>Retirement Income from Social Security</Source> </Monthly_x0020_Income_x0020_ST> <Monthly_x0020_Income_x0020_ST> <Source>Pension or retirement income from a former job</Source> </Monthly_x0020_Income_x0020_ST> <Monthly_x0020_Income_x0020_ST> <Source>Child Support</Source> </Monthly_x0020_Income_x0020_ST> <Monthly_x0020_Income_x0020_ST> <Source>Alimony or other Spousal Support</Source> </Monthly_x0020_Income_x0020_ST> </Monthly_x0020_Income>I used :Data.value('(./Data/Monthly_x0020_Income/Monthly_x0020_Income_x0020_ST/Source)[1]','varchar(50)') As [[Earned_Income],Data.value('(./Data/Monthly_x0020_Income/Monthly_x0020_Income_x0020_ST/Amount)[1]','varchar(50)') As [Earned_Income_Amount]Output looks like Earned Income, 303 which is wrong since the 303 is General Assistance (GA)My desired output is Earned Income , 0 , Unemployment Insurance, 0,etc.... ,[b]General Assistance (GA),303[/b], etc....Hopefully I wasn't too confusing!!Thanks

xp_cmdshell heartaches

$
0
0
I have a sub folder on my 2008 sql server listing backup files. All I want to do is store the file names in a temporary database set up in tempdb. I've tried many permutations using xp_cmdshell to list the folders in the sub-directory.a) I set up a bat file in the C root using a CD dos command to access the subfolder and a DIR command with a b and od option to list the files. Received 'C:\ListBatFiles.bat' is not recognized as an internal or external command when I tried to call the bat file using xp_cmdshell.b)tried using a single string with carriage return and line feed commands to accomplish the same thing in a declared varchar variable. once again xp_cmdshell was not happy. Tried double quotes, single within double and parentheses without joy. And yes I did activate xp_cmdshell in the sql server.Should I consider early retirement? Or perhaps there is an easier way to do this? Btw, this hardship is called within a stored procedure.

How to get sum to any last 7 days period of month in sql

$
0
0
I want to get sum of any last 7 days periods of month. Date Total rest of day 1-12-2016 102-12-2016 12 3-12-2016 10 4-12-2016 115-12-2016 12 6-12-2016 10 7-12-2016 11 76 (total of 7 days 1-7)8-12-2016 10 76(total of 7 days 2-8) 9-12-2016 9 73(total of 7 days 3-9)10-12-2016 10 73(total of 7 days 4-10)11-12-2016 13 75(total of 7 days 5-11) And so on.
Viewing all 16406 articles
Browse latest View live