| Author |
Topic |
|
Alaveh
Starting Member
24 Posts |
Posted - 2011-10-05 : 18:15:48
|
Hiwhen 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 Helpi 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 intas 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;GOselect 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 Saranehfrom 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 ShawSQL Server MVP |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Alaveh
Starting Member
24 Posts |
Posted - 2011-10-05 : 18:36:37
|
| i changed my codeplease check it againdelphi has an adoquery that i use .my DB is sql server |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
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 ShawSQL Server MVP |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
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 KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://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 . |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Alaveh
Starting Member
24 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
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 KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://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 ?? |
 |
|
|
Alaveh
Starting Member
24 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Alaveh
Starting Member
24 Posts |
Posted - 2011-10-05 : 19:45:28
|
| i try to do this if i canthank you tara kizer for your attention |
 |
|
|
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 ShawSQL Server MVP |
 |
|
|
|