473,322 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

getting error in pivot query

45
Hi,

I am getting error because of this line in stored procedure.How to enclose string value.
Count(Case When Totalhours<='25:0' Then EmpNo end) as Less.
25:0 is varchar datatype so i am enclosing in quotations.
Expand|Select|Wrap|Line Numbers
  1.  
  2.   ALTER PROCEDURE [dbo].[SAR_Sp_GetScheduledHours](@date1 DATETIME, @date2 DATETIME, @date3 DATETIME, @date4 DATETIME)
  3. AS
  4. DECLARE @query VARCHAR(MAX)
  5. BEGIN
  6. SET @query = 'SELECT '+ CHAR(39) + 'Forecasted HC as per Hiring Plan' + CHAR(39) + ' AS HeadCount, [' + CONVERT(VARCHAR,@date1,101) + '], [' + CONVERT(VARCHAR,@date2,101)+ '], [' + CONVERT(VARCHAR,@date3,101) + '], [' + CONVERT(VARCHAR,@date4,101) + ']' +
  7. 'FROM
  8. (SELECT WeekStartDate,
  9. Count(Case When Totalhours<='25:0' Then EmpNo end) as Less
  10. FROM TestTable1 group by WeekStartDate)
  11. AS SourceTable
  12. PIVOT
  13. (
  14. max(Less)
  15. FOR WeekStartDate IN (' + '[' + CONVERT(VARCHAR,@date1,101) + '], [' + CONVERT(VARCHAR,@date2,101)+ '], [' + CONVERT(VARCHAR,@date3,101) + '], [' + CONVERT(VARCHAR,@date4,101) + ']' + ')
  16. ) AS PivotTable'
  17. EXEC(@query)
  18. END
Oct 8 '10 #1
1 1223
Frinavale
9,735 Expert Mod 8TB
This question is better suited for a database expert.
What database management system are you using?
Oct 8 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: John | last post by:
Does anyone have any suggestions on a way to automate sending an Access pivot (query) using VBA Access and Outlook?
1
by: maneeshkhare | last post by:
I am trying to update a field in Access db (.mdb) via a DataSet using the following code. I am continously getting this error: Has anybody seen this before? 1. If I try using the same code for...
11
by: Tore Halset | last post by:
Hello. I am trying to port an old java application from MS SQL Server to PostgreSQL running on Mac OS X. I have access to the java source code and can make modifications. I have tried with...
3
by: tyngtyng | last post by:
hi... i'm new to the php and now i'm getting an error to insert my data inside the form..and also undefined index in latest_updated...... Now,i'm having trouble catching what i'm doing...
1
by: chitara | last post by:
is there any posibility to block mysql port or someting? I am getting "Error ,query failed" during adding any data through the admin panel of that website:-( same softwares(php, mysql and IIS)...
4
by: mrityunjay11 | last post by:
Error SQL query: CREATE TABLE per( item_name varchar, item_number int, payment_status int, payment_amount int, payment_currency int );
1
by: srinivasan2009 | last post by:
Hi, While Running macro i am getting error in a particular query "Numeric field overflow" For which i am opening that query and just saving the query. and query is starts executing.. ...
2
by: rajesh0303 | last post by:
Query gives error : Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression Query is : select...
3
by: Pradeep23 | last post by:
There are three computers A,B and C A is Manager' computer in which Data is stored as File System B is my desktop having SQL Server 2005 C is Main SQL Server 2005. B is able to connect to C....
1
by: NareshN | last post by:
Hi, I am getting error in following stored procedure in where condition Must declare the scalar variable "@CampaignId".I already declared CampaignId but still getting error.Please see where...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.