sql-server-2008-r2

Stored Procedure not showing fields in Crystal reports

半世苍凉 提交于 2019-12-02 01:49:29
Using: CR in VS2010, SQL Server 2008R2 I have a SP that returns results when run in SQL Server, but when I add this to a CR it doesnt show any fields in the Field Explorer. But if I try any other SP, it works fine I can see its fields. Steps I am performing: Open existing CR Right CLick Database Fields --> Database Expert --> remove the old SP --> Add the new SP A window with Enter Values pops-up, I set all to NULL and click OOK The New SP shows up in the Database expert right side I can see the new SP in the Database Fields Section in the Field Explorer. However there is no PLUS + Sign next

What are all the possible first-words of SQL statements?

偶尔善良 提交于 2019-12-02 01:13:08
问题 I'm building a user interface to be able to execute SQL statements on a SQL Server database, compatibility at SQL Server 2008 R2. I need to be able to determine whether each statement could possibly return a dataset, or if it just needs to be executed. In Delphi, the TADOQuery consists of either Open / Close for a dataset, or ExecSQL just to execute. I need to automatically determine which one to use based on the first word(s) of the SQL statement. How can I determine which method I should

How do I get a list of columns in a table or view?

不问归期 提交于 2019-12-02 01:05:10
On occasion, I'm interested in getting a list of columns in one of the tables or views in my SQL Server 2008 R2 database. It's useful, for example, if you're building database documentation without using an expensive off-the-shelf product. What's an easy way to get this information? roryap In SQL Server 2008 R2 (among other versions), there are system views provided automatically with every database. As long as you are connected to the database where your table resides, you can run a query like this: DECLARE @TableViewName NVARCHAR(128) SET @TableViewName=N'MyTableName' SELECT b.name AS

SQL Server : calculate monthly total sales incl empty months

六眼飞鱼酱① 提交于 2019-12-02 01:04:46
I'm trying to calculate the total sales of a product in a month, but I would like it to include any "empty" months (with no sales) and only select the latest 12 months. This is my code so far. declare @ProductNo int set @ProductNo = 1234 SELECT YEAR(o.OrderDate) as 'Year', MONTH(o.OrderDate) as 'Month', sum(Amount) as 'Units sold',[ProductNo] FROM [OrderLine] ol inner join [Order] o on ol.OrderNo = o.OrderNo where ProductNo = @ProductNo Group by ProductNo, YEAR(o.OrderDate), Month(o.OrderDate) Order by ProductNo, YEAR(o.OrderDate), Month(o.OrderDate) This returns Year Month Units sold 2011 6 2

Compare each records of same table in sql server and return duplicates

六月ゝ 毕业季﹏ 提交于 2019-12-02 01:00:21
问题 I have table like below.I wanted to get the duplicate records.Here the condition if date2 and date4 having same date OR dates within less than or equals to 10 days of each other then records are duplicate. I have around 2000 records in the DB.Showing here few sample example. Date1 can be ignored. It may be same date or may be different. ID Number Code Type date1 Date2 date3 Date4 status shortname CP deferred 1 EO2 C TO 9/20/2000 9/1/2010 9/18/2010 9/1/2010 Archi Ordinary 58.65586 0 2 EO2 C TO

need help to export table from sql server 2008 to text file

五迷三道 提交于 2019-12-02 00:52:45
I am trying to export a table present in ms sql server 2008 to a text file on my system. I am writing the following command in sql server query window SELECT * FROM [AdventureWorks].[Person].[AddressType] INTO OUTFILE 'C:/filename.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'; Now whenever I write this command the sql help gives me error that incorrect syntax near 'INTO' then I tried interchanging from and into keywords as follows SELECT * INTO OUTFILE 'C:/filename.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' FROM [AdventureWorks].[Person].[AddressType] ; Now it gives me

How to replace fetched values with another column while querying with SQL Server 2008 R2

蹲街弑〆低调 提交于 2019-12-02 00:20:00
问题 Alright let me explain my question with example We have 1 table This table contains Id Name Number Now example 1 House 4 2 Hospital 3 3 Airport 1 4 Station 2 Now when fetching as select * from table I want to replace third column number values with that number representing Name So example of fetching 1 House Station 2 Hospital Airport 3 Airport House 4 Station Hospital How can i do this ? thank you 回答1: select t1.id, t1.name, t2.name as name2 from your_table t1 left join your_table t2 on t1

How to find the Nearest (day of the week) for a given date

99封情书 提交于 2019-12-01 23:36:26
I been practicing queries, and my current scenario is to find the nearest Saturday for a given date. After i got the logic down, i came up with a, whats looks like a long and messy query. And I was wondering if there is a way to simplify this. Here's my query DECLARE @DATE DATE SET @DATE ='2013-09-13' IF DATENAME(DW,@DATE) = 'SUNDAY' BEGIN SELECT DATEADD(DAY,-1,@DATE) AS DATE, 'IS THE NEAREST SATURDAY' END ELSE IF DATENAME(DW,@DATE) = 'MONDAY' BEGIN SELECT DATEADD(DAY,-2,@DATE) AS DATE, 'IS THE NEAREST SATURDAY' END ELSE IF DATENAME(DW,@DATE) = 'TUESDAY' BEGIN SELECT DATEADD(DAY,-3,@DATE) AS

Why are lock hints needed on an atomic statement?

China☆狼群 提交于 2019-12-01 23:09:46
Question What is the benefit of applying locks to the below statement? Similarly, what issue would we see if we didn't include these hints? i.e. Do they prevent a race condition, improve performance, or maybe something else? Asking as perhaps they're included to prevent some issue I've not considered rather than the race condition I'd assumed. NB: This is an overflow from a question asked here: SQL Threadsafe UPDATE TOP 1 for FIFO Queue The Statement In Question WITH nextRecordToProcess AS ( SELECT TOP(1) Id, StatusId FROM DemoQueue WHERE StatusId = 1 --Ready for processing ORDER BY

Compare each records of same table in sql server and return duplicates

那年仲夏 提交于 2019-12-01 23:07:46
I have table like below.I wanted to get the duplicate records.Here the condition if date2 and date4 having same date OR dates within less than or equals to 10 days of each other then records are duplicate. I have around 2000 records in the DB.Showing here few sample example. Date1 can be ignored. It may be same date or may be different. ID Number Code Type date1 Date2 date3 Date4 status shortname CP deferred 1 EO2 C TO 9/20/2000 9/1/2010 9/18/2010 9/1/2010 Archi Ordinary 58.65586 0 2 EO2 C TO 9/20/2000 9/5/2010 9/18/2010 9/5/2010 Archi Ordinary 58.65586 0 3 EO2 C TO 9/21/2000 9/10/2010 9/18