dimanche 31 janvier 2016

How can I delete these rows and columns that were created from excel?

I have this doubt. I have charged a sheet of excel from SQL Server 2008 and this shows all the data what contains the sheet. I wish to have the data that I want and I can save these records in a some table. But I need to know How can I delete all the data that I dont need rows and columns of the sheet. Please I need you can help me.

I have it that I allow me import my sheet of Excel

select *  into #TBL_DATA  from openrowset('Microsoft.ACE.OLEDB.12.0',    'Excel 12.0; Database=C:\Microsoft\siac.xls; HDR=YES; IMEX=1', 
'select * from [Campo23$]')

This the image as shows in the query.

enter image description here

Thanks in advance.

samedi 30 janvier 2016

SQL Stored procedure returning resulr ROw Multiple time it shows 1 rows to 3 times

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[PrintQuickBill](@BillNo int)
as
SELECT  
A.BillNo, 
A.BillDate, 
A.CustomerName, 
A.Address, 
A.CustomerId, 
A.BillLaborAmt, 
A.BillPartAmt, 
A.ServTaxAmt, 
A.VatAmt,
A.BillNetAmt,

FROM         
dbo.tblQuickBillMain A

INNER JOIN
[dbo].tblQuickBillLabor L ON A.BillNo = L.BillNo
 INNER JOIN
 [dbo].tblQuickBillParts P ON  A.BillNo = P.BillNo
CROSS JOIN
dbo.CompanyInfo
where A.BillNo=@BillNo
order by CustomerName.

// this stored procedure returning result in multiple form like if I have 1 // record the result shows 3 times. // If I take BillNo=1 then it should retun only one row but it retun 3 row //which are identical means billNo 1 is shows three times with respective data.

vendredi 29 janvier 2016

How to create report table in sql?

I am creating In-patient management system desktop application in javafx as my mini project of MCA, which have some data about patient admitted in hospital. I have to save all the records of patient test & test reports in database. So, then i have created Test table with attributes ->(T_ID, P_ID, T_NAME, T_DATE) & Report table with attributes ->(R_ID, P_ID, P_NAME, T_DATE, REF_BY) So, there are multiple types of Test Report eg. CBC_REPORT, LFT_REPORT etc. then how should I create the relationship between this table. I tried but I am facing problem in USER INTERFACE for inputing values in table. Please help me becoz my project deadline is getting closer. Thanx in advance.

How I can read a sheet of Excel from sql server 2008?

Please need to help for this problem that I have. I need to read a sheet of excel from sql. I want to read this data what contains data and store in a temporal table. But right now I am having problems with read Excel because it shows me a error from sql. What I need for reading it

Error:
Not registered the OLE DB provider "Microsoft.ACE.OLEDB.12.0"

I hope you can help me with it problem, please.

I have executed it. Maybe I am missing something.

SELECT * --INTO TB_EXAMPLE FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0; Database=C:\Microsoft\Test.xls; HDR=YES; IMEX=1', 'SELECT * FROM [Plan1$]') GO

Thanks in advance.

T-SQL Distinct Close Dates

Using SQL Server 2005 I am selecting DATETIME from a set of two tables using a UNION. Many of these are very close together: e.g:

2016-01-29 10:28:57.540
2016-01-29 10:28:57.647
2016-01-29 11:23:18.193
2016-01-29 11:23:18.240

In this example I would like to get back just

2016-01-29 10:28:57.000  
2016-01-29 11:23:18.000

This is easy using some date/conversion functions to remove the ms part. However if we get the following:

2016-01-29 10:18:58.105
2016-01-29 10:18:57.952
2016-01-29 11:13:18.193
2016-01-29 11:13:18.240

I will get 3 datetimes when I only want 2:

2016-01-29 10:18:58.000
2016-01-29 10:18:57.000
2016-01-29 11:13:18.000

Instead of:

2016-01-29 10:18:58.000
2016-01-29 11:13:18.000

As 2016-01-29 10:18:58.105 and 2016-01-29 10:18:57.952 are less than a second apart.

So the question is how can I group together DATETIME values which are within a second of each other?

mercredi 27 janvier 2016

How to iterate through table for an sql job?

PerformanceReview

  • prID
  • reviewDate
  • passed
  • notes
  • successStrategy
  • empID
  • nextReviewDate

above is my table I am working with, my goal is to get the nextReviewDate check to see if it is within 7 days of the current date ( I will do this using DATEDIFF() ) and send an email to a specified email address if this condition is true.

My question is, how do I make it so that my sql job will perform this task for each performance review row in the table. I have researched and found information on CURSORS, or using WHILE loops being slow and inefficient for this task. Any help is appreciated as I am in the final stage of development :)

Sum MSSQL Count field from Grouped queryH

I am trying to write a query that takes all content from my db that has been rated higher than 3 stars and returns the top four modules based on star average and highest numbers of ratings. This part works great. But in order for me to put this into a graph, I need the percentage. So, I need the summary of the count(id_module) field. I have read through a lot of posts and tried to implement a number of solutions but have not been successful - can anyone shed any light for me? I have pasted my query below and the results it brings back - this part works fine... I just need to know how to get the sum of the id module fields - which in this case would be 23... thanks for any help offered!

SELECT TOP 4 AVG(rating) AS ratingstars, COUNT(id_module) AS countmodules,  FROM [db]
WHERE 
(rating > 3)
 GROUP BY id_module ORDER BY ratingstars DESC, countmodules DESC

ratingstars = 5, 5, 5, 5 countstar = 18, 2, 2, 1 (need the sum of these)