Export data from SQL Server 2008 R2 to CSV file format using PowerShell
Hi, I am working on exporting data from SQL Server 2008 R2 database to CSV file format. I want automate this and schedule it as a daily job. I would want to do this in PowerShell and suppress the...
View ArticleQuery from SQL to AS400 0206 and 0420 errors
I have been working on a query from out of SQL via a linked server to an AS400I seem to have 2 issues that I cannot get past.Below is the query:select * from openquery(IBM, 'SELECT T.ATTY, M.MMNBAT,...
View Articledeallocating cursor try catch
Hi. What happens if there is an error in a cursor and I don't close and deallocate the cursor in the try catch? Can this be a problem? If it is a problem how can I do to close the cursors If I have...
View ArticleYou could be September's TechNet Guru! Turbo charge your CV with awards and...
TechNet Wiki is partnering with... YOU! Give us some juicy technical content and we might big you up!It really is that simple! Show us your forum solutions or drop us some nifty snippets and become...
View ArticleHow to grant select on table-valued functions and execute on scalar-valued...
Hi Everyone,I need to grant a SQL user select permissions on all the table-valued functions and then execute on all the scalar-valued functions in a database. I've use a cursor to loop through each...
View ArticleHow to optimize this query.(its taking a quite long time to execute in my...
select Approver,BusinessUnit,Department,sum(Total) Total,sum(OnTime) OnTime,sum(Delayed) Delayed from (select distinctcasewhen t.Task_AssigneeIsGroup = 0 then t.Task_Assigneewhen...
View ArticleOptimize SQL query
Hi,I have a Transaction table having 5 billion rows.There is one SP which takes data from Transaction table based on different BL and stores in another table. Now, the issue is this SP takes almost 3-4...
View ArticleOptimizer costings for hash join versus nest loop
I have been looking at a query that involves a join between two reasonably large tables. The optimizer picks a hash join rather than a nested loop, but when I force a nested loop it uses significantly...
View ArticleSql Query Automation?
HI All,I want Automate rolling quarter logic permanently. We are loading the data every quarter and based upon billing date and paid updating the year value .Instead of adding new statement manually is...
View Articlerow numbering
Environment: SQL Server 2005, Win7Problem:I am not quit sure how to partition xid2 then number the rows for xid2 based on id1for example take a look at the following rowsid1 xid2 704729555 96857 -- 1...
View Articletable-valued function
okay I'm a bit stuck, I get this error:The last statement included within a function must be a return statement.My code:-- ================================================ -- Template generated from...
View Articleget the query with calendar day
a table has a column which contain amount with another date column so I want to get a result of query with calendar days from system even not focus if there is not any record with calendar day in the...
View ArticleCopy user mapping and server roles from one user login to another
HI All! Below is scenario I wanted to write the script for: I have login users JAP/abc, JAP/XYZ, JAP/tyu. (you can check it from SSMS-database server- security- login) And I have other logins like...
View ArticleInsert data into a SQL table from another SQL table which has data in a...
Please help me with the below scenario . Table "A": Part# shippinginfo1 ABC12 1:9.99:5.99|2:11.99:7.99 DEF34...
View ArticleWhat is the best way to get information from multiple tables?
Hello everyone. I have a ToDo Table that holds ToDo's that I have set.This is the sequel that collects the ToDo's...SELECT ToDo.ID AS TID, ToDo.ContactID, ToDo.ContactType, ToDo.ToDoType,...
View ArticleRecursive SQL query to return all rows from table with parent-child relationship
I have a table named Entity (EntityId, ParentId, Name, Address, ect ). There is a parent-child relationship with EntityId-ParentId that can go many levels deep. I would like to create return all the...
View ArticleSqlDataAdapter.Update hitting SQL Server trigger UPDATE() check
Hello,Here's my situation...I have a .NET v3.5 windows console application that uses SqlDataAdapters to add new records to a disconnected dataset and then calls .Update() on the adapater to insert all...
View ArticleAdded new TechNet WiKi article - shared useful links
Hi everybody,I'm sharing the collection of useful T-SQL links I have saved over the years in this new articlehttp://social.technet.microsoft.com/wiki/contents/articles/19670.t-sql-useful-links.aspxI'm...
View Articlecoalesce
I have a situation here, my source table is like thisCOL1COL2 COL3COL4 COL5COL6 COL7COL8 COL9COL1012 NULL4 NULL6 NULL8 9NULLNULLNULL NULL4 NULL6 NULLNULL NULL101 NULLNULLNULLNULLNULL7NULL NULLNULLmy...
View ArticleGeneral T-SQL question Help!!!
This is my problem : It involves 2 tables; Tickets and Ticket_CharacsTickets (this table has more columns, but only need these two)* ticket_id* package_id (foreign key from other...
View Article