Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Issues with first attempt at stored procedure

Author  Topic 

akc42
Starting Member

6 Posts

Posted - 2011-04-26 : 02:15:49
I am brand new to using SQL Server, although I have considerable experience of SQL programming with other (mainly Open Source) databases. I am converting an Access Application (with Access Front End against and Access Backend database) into an Access Front End with SQL Server (SQL Server 2008 R2 Express Edition). I have lots of this working, and am now trying to address certain places where I think I should do something special.

A piece of the old version of the application imports a CSV file with some "prospects" into a a local table in the front and then (in VBA) proceeds to merge them into a "Prospect" table in the main database.

I am trying to convert this into load the CSV into a temporary table and then call a stored procedure to do all the "Merge" processing.

I am currently trying to make the stored procedure, but am failing to get very far. I'll try and split all the questions into small chunks over several posts, but here are my initial ones.


- I am getting loads of error messages like

quote:
Msg 1038, Level 15, State 4, Procedure LeadsImport, Line 29
An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.


How do I count Line 29 from - If I count from the start of CREATE PROCEDURE, it comes out at the first line of this, but then later there are messages refering to line 30.




INSERT INTO [dbo].[Prospect] (
[creationDate],
[title],
[firstname],
[lastname],
[hseNoStName],
[address1],
[town],
[county],
[postcode],
[email],
[allow_email],
[allow_tel],
[callBackTime],
[source],
[gender],
[notes],
[consPeriod],
[consWhen],
[procedure],
[infoPackSent],
[infoPackRequested],
[UcFname],
[UcLname],
[UcPcode],
[leadID],
[nextAction],
[actionDue] )
SELECT
p.[Date_added_dt],
[dbo].[InitCap](p.[Title]),
[dbo].[InitCap](p.[Firstname]),
[dbo].[InitCap](p.[Lastname]),
[dbo].[InitCap](mid([dbo].[TRIM]([dbo].[TRIM](p.[House]) &" " & [dbo].[TRIM](p.[Address1])))1,60)),
[dbo].[InitCap](mid([dbo].[TRIM]([dbo].[TRIM](p.[Address2]) & " " & [dbo].[TRIM](p.[Street])),1,60)),
[dbo].[InitCap](p.[Town_City]),
[dbo].[InitCap](p.[County]),
UPPER(p.[PostCode]),
p.[Email],
p.[Allow_email],
p.[Allow_tel],
p.[Callback_range],
ISNULL(p.[Source],"Web Site"),
CASE p.[Sex] WHEN "Male" THEN "M" ELSE NULL END,
p.[Further_info],
p.[Cons_period],
p.[When],
p.[Procedure],
p.[Info_pack] = "Email",
p.[Info_pack] = "Post",
p.[UcFname],
p.[UcLname],
p.[UcPcode],
p.[leadID],
CASE
WHEN p.[consultation]="yes" THEN 2
WHEN p.[Info_pack]="Post" THEN 4
ELSE 1
END ,
p.[date_added_dt],
FROM (
SELECT
p.*
FROM [dbo].[#WebsiteLeads] p
INNER JOIN (
SELECT
MAX([leadID]) as latestLeadID,
[UcFname],
[UcLname],
[UcPcode]
FROM [dbo].[#WesSiteLeads]
GROUP BY [UcFname], [UcLname],[UcPcode]
) W
ON p.[leadID] = W.[latestLeadID]
) AS p
LEFT JOIN [dbo].[Prospect]
ON
p.[UcFname] = [dbo].[Prospect].[UcFname]
AND p.[UcLname] = [dbo].[Prospect].[UcLname]
AND (Coalesce(p.[UcPcode],"") = "" OR p.[UcPcode] = [dbo].[Prospect].[UcPcode] )
WHERE [dbo].[Prospect].[UcFname] IS NULL AND [dbo].[Prospect].[UcLname] IS NULL;


What does the error message mean anyway. I can't see what is wrong with this

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2011-04-26 : 05:10:10
Symbol " is not accepted in SQL use ' instead.

Vaibhav T

If I cant go back, I want to go fast...
Go to Top of Page

akc42
Starting Member

6 Posts

Posted - 2011-04-26 : 05:25:03
I think I have understood what is wrong

Strings need to be delimited via ' characters not " characters.

In fact, they are unicode, so N' ... ' characters are needed.

A vast number of the error messages have disappeared when I did this
Go to Top of Page

akc42
Starting Member

6 Posts

Posted - 2011-04-26 : 05:26:54
quote:
Originally posted by vaibhavktiwari83

Symbol " is not accepted in SQL use ' instead.

Vaibhav T

If I cant go back, I want to go fast...



Thanks - I think your reply must have come just as I had figured it out for myself, so sorry I just repeated what you said just below.
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2011-04-26 : 05:28:24
No problem

Vaibhav T

If I cant go back, I want to go fast...
Go to Top of Page
   

- Advertisement -