|
thanx for helping bob
i saw now that i had a mistake
this is working below,
SELECT @vSQL = 'INSERT INTO #rapor(S'+ convert(varchar, @SNO) + ') VALUES('''+convert(varchar, @SONUC) +''')'
an by the way how can i see what value in my variable
i mean like c# Console.WriteLine(@vSQL) and it writes
INSERT INTO #rapor(S10) VALUES(' f ')
how can do with tsql
thanks again
Sampiyon FENERBAHCE
|
|
|
|
|
TALHAKOSEN wrote: thanx for helping bob
No problem, always happy to help.
TALHAKOSEN wrote: how can i see what value in my variable
If running in query analyser
print @vSQL
or simply
select @vSQL
Bob
Ashfield Consultants Ltd
|
|
|
|
|
declare @vSQL varchar(1000)
DECLARE @SNO INT;
DECLARE @SNO2 INT;
DECLARE @KNO INT;
DECLARE @SONUC VARCHAR(10);
SET @SNO = 10;
SET @SNO2 = 10;
WHILE @SNO < 83
BEGIN
DECLARE ankcev_cursor SCROLL CURSOR FOR
SELECT KULLANICINO FROM AnketCevap WHERE ANKETID='7'
OPEN ankcev_cursor
FETCH NEXT FROM ankcev_cursor INTO @KNO
WHILE @@FETCH_STATUS = 0
BEGIN
--SELECT CEVAPSIK FROM ANKETCEVAP WHERE ANKETID='7' AND KULLANICINO = @KNO AND SORUNO=@SNO
SET @SONUC=(SELECT CEVAPSIK FROM ANKETCEVAP WHERE ANKETID='7' AND KULLANICINO = @KNO AND SORUNO=@SNO)
SELECT @vSQL = 'UPDATE #rapor SET S'+ convert(varchar, @SNO)+'='''+ convert(varchar, @SONUC)+''' where ID='''+ convert(varchar, @KNO) + ''''
Execute (@vSQL)
FETCH NEXT FROM ankcev_cursor INTO @KNO
END
CLOSE ankcev_cursor
DEALLOCATE ankcev_cursor
SET @SNO = @SNO+1;
END
PRINT @vSQL
PRINT @SNO ------ALWAYS WRITE S10 why stay same value ????
Sampiyon FENERBAHCE
|
|
|
|
|
Don't know. I took your code and commented out all the bits that wouldn't run and it printed 83.
declare @vSQL varchar(1000)
DECLARE @SNO INT;
DECLARE @SNO2 INT;
DECLARE @KNO INT;
DECLARE @SONUC VARCHAR(10);
SET @SNO = 10;
SET @SNO2 = 10;
WHILE @SNO < 83
BEGIN
-- DECLARE ankcev_cursor SCROLL CURSOR FOR
-- SELECT KULLANICINO FROM AnketCevap WHERE ANKETID='7'
-- OPEN ankcev_cursor
--
-- FETCH NEXT FROM ankcev_cursor INTO @KNO
--
-- WHILE @@FETCH_STATUS = 0
-- BEGIN
-- --SELECT CEVAPSIK FROM ANKETCEVAP WHERE ANKETID='7' AND KULLANICINO = @KNO AND SORUNO=@SNO
-- SET @SONUC=(SELECT CEVAPSIK FROM ANKETCEVAP WHERE ANKETID='7' AND KULLANICINO = @KNO AND SORUNO=@SNO)
-- SELECT @vSQL = 'UPDATE #rapor SET S'+ convert(varchar, @SNO)+'='''+ convert(varchar, @SONUC)+''' where ID='''+ convert(varchar, @KNO) + ''''
-- Execute (@vSQL)
-- FETCH NEXT FROM ankcev_cursor INTO @KNO
-- END
--
-- CLOSE ankcev_cursor
-- DEALLOCATE ankcev_cursor
SET @SNO = @SNO+1;
END
PRINT @vSQL
PRINT @SNO ------ALWAYS WRITE S10 why stay same value ????
Bob
Ashfield Consultants Ltd
|
|
|
|
|
ok ok i see now my mistake
SELECT KULLANICINO FROM AnketCevap WHERE ANKETID='7' and <soruno> i forget to add this
so it takes to long times to return back ))
anyway thanks for your patience on me )) thank a lot...
Sampiyon FENERBAHCE
|
|
|
|
|
Thats OK
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi
QUESTION:
Why is the code running so slow and what can I do to improve it?
THE CODE:
$currentTable = "SS_products";
$q1 = db_query("SELECT FLOOR(RAND() * COUNT(*)) AS rand_row FROM ".
$currentTable) or die (db_error());
$row1 = db_fetch_row($q1);
$q2 = db_query("SELECT categoryID, name, default_picture FROM ".
$currentTable." WHERE categoryID=7 Limit $row1[0], 1") or die (db_error());
Background Infomation on the Code:
I have a website where I use a shopping cart system called ShopScript Premium. This system works more then fine with my current webhost BlueHost. But a problem arises when I add customized the code.
I have added to the website home page that every time the browser is refreshed 10 new random products will be the customers. The ShopScript system only offers products which are to be changed by the administrator manually. When the code for the random product is executed the website runs considerably slower then without the random products, although sometimes and does run with no problems and fast speed for a minute or so. Even if the user is using the other pages the website is still slow. I suspect this has to do with the fact that the ShopScript system uses a smarty engine, although that does not fully explain why.
In my database the table called has 1373 rows. I use the code above to randomly select one of the rows to be viewed on the website. According to my log on mySQL slow queries, the above mentioned code, is the source of the problems. The log states that the code uses 2 to 4 seconds query time. My webhost does not allow any single process taking more than 30 CPU seconds to run or if the total processes take more than 40 CPU seconds in any 60 second window to avoid server lockups. Such an event triggers a CPU Quota/Suspension Error, where my website is accessable for 5 to 10 minutes. This is a big problem as I lose customers this way.
On before hand
Thank you for your help
|
|
|
|
|
Count(*) is always slow. Try to use a different seed for generating your random number. If it's SQL Server 2005, you can use sys.sysindexes to get the rowcount.
|
|
|
|
|
If you don't need a really random record why not just select a record based on something like
select datediff(ms,getdate(), dateadd(hour, datepart(ss,getdate()),getdate()))
This may not be random enough, but you get the idea .
Bob
Ashfield Consultants Ltd
|
|
|
|
|
i need to get report from a table which has questionId field, studentId, inquiryId like that and there are 80 questions and 300 students replied this inquiry. I need a result like below (question=q)
inqueryId studentId q1 q2 q3 q4 q5 ..... q79 q80
7 123 a b b c d e c
7 245 b c d e e c c
i create temporary table has 80 question field but i cant fill it from my original table
Sampiyon FENERBAHCE
|
|
|
|
|
U need to craete a dynamic query for inserting data in the table like
declare @Dynstr varchar(4000)
set @Dynstr ='update #TempDyamicWeek
SET col'+cast(@count1 as varchar(10)) +' =#TempDurByWeek.duration
from #TempDyamicWeek inner join #TempDurByWeek on
#TempDyamicWeek.userid= #TempDurByWeek.userid
and #TempDyamicWeek.type=#TempDurByWeek.type
and #TempDurByWeek.WeekEnding= '''+convert(varchar(30),@CurDateTo,121)+''''
exec (@Dynstr)
please coorect the colume name according to yours..
Thanks
Hem
|
|
|
|
|
thanks a lot
Sampiyon FENERBAHCE
|
|
|
|
|
Hi all,
I want to learn that, can i change name of variable, i mean i wanna have
@s1, @s2, @s3 ... @s20 but i dont wanna write it wanna use
WHILE X<20
BEGIN
DECLARE @SX
X=X+1;
END
CAN I DO THAT pls help
Sampiyon FENERBAHCE
|
|
|
|
|
Can't be done.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
When using SQL as the way you described, no.
However, if you use dynamic SQL, meaning you create a string that contains the SQL statement and execute it, this can be done.
The need to optimize rises from a bad design
|
|
|
|
|
What is mysql and what is ado.net
|
|
|
|
|
Hi,
MYSQL is a open source database management system.
For more details please visit the following link:
What is MySQL[^]
ADO.NET stands for ActiveX Data Objects for .NET. It refers to the suite of data access technologies used to manipulate databases. ADO.NET is part of the .NET Framework.
For more details please visit the following link:
What is ADO.Net[^]
Hope this helps .
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
Hello Friends,
I have a table named Table1 and a column named CreationTime.
CreationTime has the datatype as datetime.
It gives the output as mm/dd/yyyy hh:mm:ss
But I want the output as hh:mm:ss
I am aware that I can use CAST or CONVERT function, but I am not getting a proper syntax for the same.
I would appreciate if anyone of you could help me to get the current syntax for what I wish to achieve.
Thank you,
notes4we
|
|
|
|
|
notes4we wrote: I am not getting a proper syntax for the same.
What does that mean?
SELECT CONVERT (varchar, CreationTime, 108) FROM Table1
ought to do it...
|
|
|
|
|
Thank you. I am able to get the desired output now.
|
|
|
|
|
|
?? ADO.NET is not a database.
|
|
|
|
|
Anyone has experience getting it to work? When I tried to configure an ODBC database source, there is a dropdown list that is supposed to have all existing (oracle) services defined on your machine. For me, this dropdown list contains unreadable characters. If I ignore this dropdown and type in my service name, it won't work either.
Does anyone have the same problem?
|
|
|
|
|
Hi fellow coders!
I'm in a desperate need for some help in the form of code to convert opc-data to ODBC-data, does anyone know how this has to be done.
My main problem is that I shall picksome specific parameters from the OPC stream and send that data to an ODBC source.
TIA
Kind regards
Carsten
|
|
|
|
|
Are you meaning Open Packaging Conventions with OPC?
If you are, I believe that the only way is to write custom logic that reads the data, extracts the needed info and sends relevant data to target using ODBC.
The need to optimize rises from a bad design
|
|
|
|