Friday, April 5, 2013

[SQL server issues]Created Issue: AdventureWorksDW2012 Download file corrupt [19063]

There seams to be an issue with the AdventureWorksDW2012 Data file download. When I try to run this SQL statement:

CREATE DATABASE AdventureWorksDW2012 ON (FILENAME = 'E:\MSSQL11.SQL02\MSSQL\DATA\AdventureWorksDW2012_Data.mdf') FOR ATTACH_REBUILD_LOG;

This is the error I get:

Msg 5172, Level 16, State 15, Line 1
The header for file 'E:\MSSQL11.SQL02\MSSQL\DATA\AdventureWorksDW2012_Data.mdf' is not a valid database file header. The FILE SIZE property is incorrect.

Thanks,Dan

There seams to be an issue with the AdventureWorksDW2012 Data file download. When I try to run this SQL statement:

CREATE DATABASE AdventureWorksDW2012 ON (FILENAME = 'E:\MSSQL11.SQL02\MSSQL\DATA\AdventureWorksDW2012_Data.mdf') FOR ATTACH_REBUILD_LOG;

This is the error I get:

Msg 5172, Level 16, State 15, Line 1
The header for file 'E:\MSSQL11.SQL02\MSSQL\DATA\AdventureWorksDW2012_Data.mdf' is not a valid database file header. The FILE SIZE property is incorrect.

Thanks,Dan


.

sqlserversamples.codeplex.com

[T-SQL] How to get result sets when using dynamic query

[T-SQL] How to get result sets when using dynamic query


How to get result sets when using dynamic query

Posted: 05 Apr 2013 01:15 AM PDT

This procedure returns ID and Question ID . I previously was sending data at application level by appending them in varchar variable but in dynamic query m unable to do it. I tried to get the resultset at application level by ISingleResult as i have connected application through Linq to SQL but it is also not working please help . CREATE PROCEDURE [dbo].[Get_Ques_id_for_can](@candidate_id varchar(max),@Exam_id varchar(max),@sec_id bigint,@Q_id varchar(max) OUTPUT)ASBEGINdeclare @table_query varchar(max)declare @table varchar(max)set @table=@candidate_ID+@Exam_iddeclare @id varchar(50)declare @ques_id varchar(50)set @table_query='SELECT [ID], [Question_ID] FROM ['+@table+'] WHERE [Section_ID]='+CONVERT(varchar(50),@sec_id)EXEC(@table_query)END

Need urgent help

Posted: 04 Apr 2013 11:26 PM PDT

Hi All,I have a table like this. but its have 5-6k rows.1 AppName2 AppVersion3 Product4 Date15 Date26 Date37 AppName8 AppVersion9 Product10 Date111 Date212 Date313 AppName14 AppVersion15 Product16 Date117 Date218 Date3.....and I want result like this. the logic is that after each 6 records we have a complete row. you can also say that column name are associated with records.AppName AppVersion Product Date1 Date2 Date31 2 3 4 5 67 8 9 10 11 1213 14 15 16 17 18Thanks for your help.Sneh

How to get all 7 days Name in One table.

Posted: 04 Apr 2013 02:46 AM PDT

I am working on one report which showing all days name as column.but Now I am getting some bugs.If for particular day data is not available on table then that days name are missing on report and which is not good.If table doesn't have that day data even we want to show that day column as null.can any one help me out with this???

Passing Multiple Values As Parameters to get Multiple Columns with Comma Seperation(MSSQL)

Posted: 04 Apr 2013 10:06 PM PDT

Create procedure temp(@MID smallint)asBeginselect TranID,[MonthValue]=(CASE WHEN @MID=1 THEN Jan WHEN @MID=2 THEN Feb WHEN @MID=3 THEN Mar WHEN @MID=4 THEN Apr WHEN @MID=5 THEN May WHEN @MID=6 THEN Jun WHEN @MID=7 THEN Jul END) FROM TblTran as M where TranID=1 and M.Month = @MIDendThis is a stored procedure with a parameter @MID that i'm using to generate a report using SSRS.If a single value is passed to the parameter it works fine.For example-Transaction Table[b][u]TranID | Apr | May | Jun | Jul [/u][/b] 1 | 50 | 30 | 11 | 30 2 | 51 | 39 | 100 | 30if i execute with[b]Exec 4[/b]the result is what i expect[b][u]TranID | MonthValue [/u] [/b] 1 | 50 **-- ie Aprils value**But I need to pass multiple values to the parameterlike[b]exec 4,5,6[/b]and desired result should be[u][b]TranID | MonthValue [/b] [/u] 1 | 50,30,11 ***-->Comma Separated values of columns how can i acheive result like this??

Concatenate fields by specifying the start position of the next filed

Posted: 04 Apr 2013 08:27 PM PDT

Hi,how do I Concatenate fields by specifying the start position of the next filed.e.g. I have table_x with three columnsNameLastNameEmpnoI would like to concatenate the three so that I only get one line. but I would also like to specify the length of the column and where the next column would start.

query help

Posted: 04 Apr 2013 07:37 AM PDT

Hi Please help for below requirement.I need to combine two columns of data and insert in new columnex: if have col1 has 1, 2, 3 and col2 has 1, 2, 3 and i need new column as col3 by combining col1 and col2 like 11, 22, 33I have two columns liek belwocol1 col21 2 1 56 12 7I need table like belowCol1 col2 col31 2 121 5 156 1 622 7 27ThanksAswin

TSQL to get users and permissions

Posted: 04 Apr 2013 03:26 AM PDT

I would like to use the below code in a cursor and loop through each and every database in an instance. Now I want to select the name of the database along the with the details the script selects. Is this possible?[code="sql"]select [Login Type]=case sp.typewhen 'u' then 'WIN'when 's' then 'SQL'when 'g' then 'GRP'end,convert(char(45),sp.name) as srvLogin, convert(char(45),sp2.name) as srvRole,convert(char(25),dbp.name) as dbUser,convert(char(25),dbp2.name) as dbRolefrom sys.server_principals as sp joinsys.database_principals as dbp on sp.sid=dbp.sid joinsys.database_role_members as dbrm on dbp.principal_Id=dbrm.member_principal_Id joinsys.database_principals as dbp2 on dbrm.role_principal_id=dbp2.principal_id left join sys.server_role_members as srm on sp.principal_id=srm.member_principal_id left joinsys.server_principals as sp2 on srm.role_principal_id=sp2.principal_id[/code]

Get the one set of values from the same table

Posted: 04 Apr 2013 03:20 AM PDT

Hi,I have a table which has following columnsShipmentID, ProductID, ProductType,QtyNow I want to select only those records which has only productTypeID = 2 for exampleShipmentID ProductID ProductType Qty1 1 2 101 2 2 51 3 3 12 1 2 102 2 2 5The query should return only ShipmentID = 2, because that set only has producttypid = 2. I want to avoid those rows if it has at least one producttypeid = 3.I tried different queries but it's not giving me the perfect result.Can anybody help me out please?Thanks.Thanks.Gunjan.

[SQL Server Data Warehousing]Pricing of PDW Appliance


Hi All:


I have been searching hard for the pricing & details of SQL SERVER 2012 PDW Appliance (both Dell and HP) but got nothing. Can anyone show me where i can find some relevant info?


Cheers



.

social.technet.microsoft.com/Forums

[SQL Server Data Warehousing]Replace function ineffective with the string more than 90 chars


Hi,


I am working on T-SQL stored procedure. In my code i use REPLACE function. It works fine until i pass the string of length more than 90 characters.


where geography in (''' + REPLACE(@Geography,',',''',''') + '''' + ')'


The geography value is passed from SSRS report, where i send the parameter with the JOIN function using comma seperator. In this stored procedure i frame the multivalued parameter using the replace function. I have tried changing the parameter resolution to nvarchar(500) no changes notified


The problem is that it is working ABSOLUTELY fine until i pass  @Geography with more than 90 characters.



Bunch of thanks ~ Deva ~ 




.

social.technet.microsoft.com/Forums

[SQL Server Data Warehousing]A Problem in time


Hi Guys,


Im having a bit of a conundrum and am seeking some best practise advice.


I have a fact table for phone call periods on any given day with call duration as a measure, calls can go over midnight and my time dimension has a grain of minutes.


Im not sure how to note the calls going over midnight, given that the calls go over midnight the call will have to be split in 2 one running to midnight and the second spanning from midnight to call end.


The problem is that with my time dimension running in minutes this will have to end at 23.59 which will leave my meausre a minute short of accurate.


eg call date,      call start , call end, call duration


     02/04/2012  23:45       23:59         14


     03/04/2012 00:00       00:05          5


giving a misleading 19 minute call duration


alternatively


eg call date,      call start , call end, call duration

     02/04/2012  23:45       00:00         15


     03/04/2012 00:00       00:05          5


this is equally misleading as 00:00 refers to 03/04 instead of the 02/04  and the call will have ended 23hrs 45 minutes before it started.


if i add a call enddate of 03/04/2012 to the fact table that still invalidates the grain of the table of call periods per day.


any advice will be greatly appreciated.


ill also be happy to clarify any ambiguities.


BB



.

social.technet.microsoft.com/Forums

[SQL Server Data Warehousing]Where to find best practices for tuning data warehouse ETL queries?


Hi Everybody,


Where can I find some good educational material on tuning ETL procedures for a data warehouse environment?  Everything I've found on the web regarding query tuning seems to be geared only toward OLTP systems.  (For example, most of our ETL queries don't use a WHERE statement, so the vast majority of searches are table scans and index scans, whereas most index tuning sites are striving for index seeks.)


I have read Microsoft's "Best Practices for Data Warehousing with SQL Server 2008R2," but I was only able to glean a few helpful hints that don't also apply to OLTP systems:


  • often better to recompile stored procedure query plans in order to eliminate variances introduced by parameter sniffing (i.e., better to use the right plan than to save a few seconds and use a cached plan SOMETIMES);

  • partition tables that are larger than 50 GB;

  • use minimal logging to load data precisely where you want it as fast as possible;

  • often better to disable non-clustered indexes before inserting a large number of rows and then rebuild them immdiately afterward (sometimes even for clustered indexes, but test first);

  • rebuild statistics after every load of a table.

But I still feel like I'm missing some very crucial concepts for performant ETL development.


BTW, our office uses SSIS, but only as a glorified stored procedure execution manager, so I'm not looking for SSIS ETL best practices.  Except for a few packages that pull from source systems, the majority of our SSIS packages consist of numerous "Execute SQL" tasks.


Thanks, and any best practices you could include here would be greatly appreciated.


-Eric



.

social.technet.microsoft.com/Forums

[SQL Server Data Warehousing]CDC function should generate an error, but doesn't


When I execute this following code, the null as the second parameter to the get_all_changes function should generate an error back to the user.  However, it doesn't.  It just returns an empty result set.  If I don't have a where clause, it does generate the expected error.  Does anyone know why this behaves in this manner?



SELECT *
FROM cdc.fn_cdc_get_all_changes_dbo_Table1(0x01, null, 'all')
WHERE
CAST(sys.fn_cdc_is_bit_set(1, __$update_mask) AS int) >0

Thanks,


Jason



.

social.technet.microsoft.com/Forums

Search This Blog