You have do with this way
try this following
- Right click on database >
- Tasks >
- Generate Scripts >
- Select the objects you wish to script( Store-Procedure or table ) >
- Script to File ( Where you got the script code details) >
- Set schema or data or schema with data for Table (if you take a sp , then don't set anything)
- Run generated scripts against target database .
If you need to move this by using query, then look at this link :
Copy all SP's from one Database to another Database using a script
Update:
...........
Here is a 4 option for move the Stored-procedure '
Option 1: Use the scripting wizard Right-click the db --> tasks --> Generate scripts --> go through the wizard.
Option 2: Open the stored procedures folder in SSMS (in the object explorer details window). (You can also press F7 to do so, see this blog for details). You can use shift+click to select all the stored procedures and you can then right-click and script them to a file.
Options 3: The simplest of them.
bcp "SELECT definition + char(13) + 'GO' FROM MyDatabase.sys.sql_modules s INNER JOIN MyDatabase.sys.procedures p ON [s].[object_id] = [p].[object_id] WHERE p.name LIKE 'Something%'" queryout "c:\SP_scripts.sql" -S MyInstance -T -t -w
Option 4 : To script All the Stored Procedures in the Database
SELECT O.Name as ProcName
,M.Definition as CreateScript
,O.Create_Date
,O.Modify_Date
FROM sys.sql_modules as M INNER JOIN sys.objects as O
ON M.object_id = O.object_id
WHERE O.type = 'P'
If the Stored Procedure is created with ENCRYPTION option then you will get the NULL in the definition column.