mercredi 4 mars 2015

sql support for my application in c#

i've created a small application which includes data.sqlclient ,so my question is that when i m running my application in another machine which doesnt have an sql installed should i be using any thing like sql runtime or something lyk tat .. please help me


THANKS IN ADVANCE.... :)


Show Query Results in Month/Year Order

I have a query that sales and it shows the month and year (field names are salemonth & saleyear) of the sale. Example return-set would be



January 2014
February 2014
March 2014
December 2014
January 2015


Now obviously I can't set it that way in my straight query as if I try to order by salemonth ASC it woudl show December, February, january, january, March. or even if I order by year ASC it still would not show in the actual calendar month order. How can I sort this result set to show in the order of an actual calendar?


One caveat their may be 0 sales for the month (november for example) I would still want this month/year shown in the query but have a 0 shown. Is this achievable?


Groovy Sql in Grails project to access SqlServer classpath issue

Environment: Windows 7 Enterprise, SP1, 64-bit, IntelliJ Ultimate 14.0.3, build #IU-139.1117, Java jdk 1.8.0_3


I'm trying to migrate data from Sql Server. It is not necessary to define a datasource. This works with Groovy standalone, but not in Grails: def sql = Sql.newInstance( 'jdbc:jtds:sqlserver://OSSA:1433/LTT;domain=camp', 'dxg151430', ***', 'net.sourceforge.jtds.jdbc.Driver' ) With Groovy, I put the driver jar, jtds-1.3.1.jar on the classpath. In Grails, I added this dependency to the BuildConfig.groovy: runtime "net.sourceforge.jtds:jtds:1.3.1" I Grails I get "No suitable driver found for jdbc:jtds:sqlserver://OSSA:1433/LTT;domain=camp". I had the same error message with Groovy standalone, before I added the .jar to the classpath. I've also tried to add the .jar to the Grails lib folder. And yes, with both options, dependency declaration or lib folder, I did "Grails compile --refresh-dependencies". Tried it from CMD and within the IDE.


SQL server corrupt log file attempted restore, want to continue with next file

Our live instance of SQL server 2005 crashed last night but managed to write out a corrupted transaction log file.


Partial results from RESTORE HEADERONLY commands below:



193000.trn OK - First LSN 140773000030325500001 / Last LSN 140773000304635700001

195224.trn Corrupted *Incomplete*

203000.trn OK - First LSN 140773000304635700001 / Last LSN 140773001216537800001


So it looks to me as though I should be able to ignore the 195224.trn file to continue the log restore. Unfortunately our automated log restore job tried to restore the 195224.trn file and of course got an error.


So now when i try to run



RESTORE LOG [dbname] FROM DISK =N'H:\Logs\203000.trn' WITH NORECOVERY


I get the below error



A previous restore operation was interrupted and did not complete processing on file 'log'. Either restore the backup set that was interrupted or restart the restore sequence.


I have tried running both this file and the previous OK file WITH RESTART but that has not worked.


Is there anything else I can do without having to resort to something slower like restore using diff?


mardi 3 mars 2015

TSQL Pivot with combination result

I have data in SQL server 2005 table similar to below format.



OrderNo ProductId Sale
----------------------
1 A £10
2 B £20
3 C £30
4 A £10
4 B £20
5 A £10
5 B £20
6 C £30
6 B £20
7 C £30


I need to write TSQL query that would give me result table in this format.



NoOfOrders 'A' SaleValue 'B' SaleValue 'C' SaleValue
------------------------------------------------
Prod A (Only) 1 £10
Prod B (Only) 1 £20
Prod C (Only) 2 £60
Prod A & B 2 £20 £40
Prod A & C 0 £0 £0 £0
Prod B & C 1 £20 £30


Any idea greatly appreciated.


lundi 2 mars 2015

Need help to create file with name and current time stamp

I need to create .xlsx file exporting data from sql database and file name would be 'FileName' and current yyyymmdd.


I'm using following code.


declare @filepath nvarchar(4000); set @filepath = '\file1\Shared\Buying Report\NewFile' + CAST(YEAR(CURRENT_TIMESTAMP) AS VARCHAR)+ RIGHT('00'+CAST(MONTH(CURRENT_TIMESTAMP) AS VARCHAR),2)+ RIGHT('00'+CAST(DAY(CURRENT_TIMESTAMP) AS VARCHAR),2)+'.xlsx'


EXEC p_CreateExcel @db_name='st01', @table_name = 'Austomate_report', @file_name = @filepath


I enabled xP_cmdshell on my server also give right permission to destination folder and File got created at provided path with YYYYMMDD but not getting data copy on the file. Let me show you what's it shows me.


1,output NULL Starting copy... NULL 1 rows copied. Network packet size (bytes): 4096 Clock Time (ms.) Total : 1 Average : (1000.00 rows per sec.) NULL


2,output


NULL Starting copy... 1000 rows successfully bulk-copied to host-file. Total received: 1000 1000 rows successfully bulk-copied to host-file. Total received: 2000 1000 rows successfully bulk-copied to host-file. Total received: 3000 NULL 3741 rows copied. Network packet size (bytes): 4096 Clock Time (ms.) Total : 94 Average : (39797.87 rows per sec.) NULL


3,


output The system cannot find the path specified. NULL


Search and Replace a a partial string / substring in mssql tables

I was tasked with moving an installation of Orchard CMS to a different server and domain. All the content (page content, menu structure, links, etc.) is stored in an MSSQL database. The good part: When moving the physical files of the Orchard installation to the new server, the database will stay the same, no need to migrate it. The bad thing: There are lots and lots of absolute URLs scattered all over the pages and menus.


I have isolated / pinned down the tables and fields in which the URLs occur, but I lack the (MS)SQL experience/knowledge to do a "search - replace". So I come here for help (I have tried exporting the tables to .sql files, doing a search-replace in a text editor, and then re-importing the .sql files to the database, but ran into several syntax errors... so i need to do this the "SQL way").


To give an example:


The table Common_BodyPartRecord has the field Text of type ntext that contains HTML content. I need to find every occurance of the partial string /oldserver.com/foo/ and replace it with /newserver.org/bar/. There can be multiple occurances of the pattern within the same table entry.


(In total I have 5 patterns that will need replacing, all partial string / substrings of urls, domains/paths, etc.)


I usually do frontend stuff and came to this assignment by chance. I have used MySQL back in the day I was playing around with PHP related stuff, but never got past eh basics of SQL - it would be helpful if you could keep your explainations more or less newbie-friendly.


The SQL server version is SQL Server 9.0.4053, I have access to the database via the Microsoft SQL Server Management Studio 12


Any help is highly appreciated!