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
 GO

Author  Topic 

Alaveh
Starting Member

24 Posts

Posted - 2011-10-05 : 18:15:48
Hi

when i use GO at the end of my function receive an error ( Incorrect syntax near GO )

if i remove GO from Function i will receive a new error ( Incorrect syntax near the keyword select )

its more than 6 days i cant write this damn code ,,, i was posted it in more than 4 forums that are not useful .

some one just help me please . F1 F1 help Help

i use delphi xe and sql server . can i change this function with no GO ???

my query :


create function getSumBSen2(@pfcode INT, @pdcode INT, @pSen INT) returns int
as begin declare @r int;
select @r= sum(t2.t_shab + t2.t_rooz) from tbl_talafat_dan t2 where t2.FCode = @pfcode and t2.DCode = @pdcode and t2.sen <= @pSen;
return (@r); end;
GO
select t1.sen, sum(t1.d_rooz) as d1, sum(t1.d_shab) as d2, sum(t1.d_rooz + t1.d_shab) as d_sum,
Round((sum((1000*(t1.d_rooz+t1.d_shab)+0.01)/(100-(dbo.getSumBSen2(81, 1, t1.sen))))),1) as Saraneh
from tbl_talafat_dan t1 where t1.FCode =81 and t1.DCode = 1 group by t1.sen;

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-10-05 : 18:26:25
Your code parses successfully. I can't try running it since I don't have the tables.

What's the second query (after the GO)? It's not part of the function but it doesn't use the function, so I can't figure out why it's here.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-05 : 18:29:21
What is delphi xe? Are you using Microsoft SQL Server?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Alaveh
Starting Member

24 Posts

Posted - 2011-10-05 : 18:36:37
i changed my code

please check it again

delphi has an adoquery that i use .

my DB is sql server
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-05 : 19:02:25
Have you tried running your code inside Management Studio?

Also, please do not open up new topics. I have locked your duplicate. Please edit your OP to include the code.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-10-05 : 19:25:24
Your changed code still parses fine, no errors at all.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-05 : 19:31:15
Parses fine for me too. My guess is that Alaveh is trying to run the bit of code in Delphi and Delphi doesn't like the function syntax or the go.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Alaveh
Starting Member

24 Posts

Posted - 2011-10-05 : 19:32:56
quote:
Originally posted by tkizer

Have you tried running your code inside Management Studio?

Also, please do not open up new topics. I have locked your duplicate. Please edit your OP to include the code.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


How can i run my code inside Management Studio ? what is Management Studio ? you mean sql server ? in sql server it works well with no error but i need to run it from ado connection . ado cant recognize GO in query . how can i run my function without GO ?

and sorry for duplicate .
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-05 : 19:34:46
Management Studio is the client tool for SQL queries. You should create your objects using that tool.

If you must use Delphi, then run them in separate batches so that the go isn't required.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Alaveh
Starting Member

24 Posts

Posted - 2011-10-05 : 19:35:06
quote:
Originally posted by GilaMonster

Your changed code still parses fine, no errors at all.

--
Gail Shaw
SQL Server MVP



quote:
Originally posted by tkizer

Parses fine for me too. My guess is that Alaveh is trying to run the bit of code in Delphi and Delphi doesn't like the function syntax or the go.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



yes , my promlem is for GO

dont tell me you cant help . i dont know what to do .
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-05 : 19:38:54
Why do you need to use Delphi? It doesn't seem to support what you are trying to do.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-05 : 19:39:14
Did you try running them in separate batches like I mentioned?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Alaveh
Starting Member

24 Posts

Posted - 2011-10-05 : 19:39:56
quote:
Originally posted by tkizer

Management Studio is the client tool for SQL queries. You should create your objects using that tool.

If you must use Delphi, then run them in separate batches so that the go isn't required.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



it cant be 2 queries tara . i tried to make it one but the sql server doesnt let me use sub query with group by . and i cant run first part and save result and then run second part because i need result of first part for run second part for each record .

can you find a way ??
Go to Top of Page

Alaveh
Starting Member

24 Posts

Posted - 2011-10-05 : 19:41:40
quote:
Originally posted by tkizer

Why do you need to use Delphi? It doesn't seem to support what you are trying to do.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



oh my god

tara i wrote more than 10,000 lines from this project :D

i cant change my programming language now .
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-05 : 19:43:26
Get Management Studio installed. Create the function in there and then reference it in Delphi.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Alaveh
Starting Member

24 Posts

Posted - 2011-10-05 : 19:45:28
i try to do this if i can

thank you tara kizer for your attention

Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-10-06 : 05:18:44
quote:
Originally posted by Alaveh

it cant be 2 queries tara . i tried to make it one but the sql server doesnt let me use sub query with group by .



But they are already two queries. The GO is a batch-breaker, those two queries are sent separately to SQL Server. The function ends at the GO, the second query is just that, a completely separate second query.

What are you trying to do here?

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -